Exemple #1
0
  @Override
  public void setup(ProfilerPluginSetupContext context) {
    final UserPluginConfig config = new UserPluginConfig(context.getConfig());

    // add user include methods
    for (String fullQualifiedMethodName : config.getIncludeList()) {
      try {
        addUserIncludeClass(context, fullQualifiedMethodName);
        if (logger.isDebugEnabled()) {
          logger.debug("Add user include class interceptor {}", fullQualifiedMethodName);
        }
      } catch (Exception e) {
        logger.warn("Failed to add user include class(" + fullQualifiedMethodName + ").", e);
      }
    }
  }
Exemple #2
0
  private void addUserIncludeClass(
      ProfilerPluginSetupContext context, final String fullQualifiedMethodName) {
    final String className = toClassName(fullQualifiedMethodName);
    final String methodName = toMethodName(fullQualifiedMethodName);

    context.addClassFileTransformer(
        className,
        new TransformCallback() {

          @Override
          public byte[] doInTransform(
              Instrumentor instrumentContext,
              ClassLoader classLoader,
              String className,
              Class<?> classBeingRedefined,
              ProtectionDomain protectionDomain,
              byte[] classfileBuffer)
              throws InstrumentException {
            InstrumentClass target =
                instrumentContext.getInstrumentClass(classLoader, className, classfileBuffer);

            for (InstrumentMethod method :
                target.getDeclaredMethods(MethodFilters.name(methodName))) {
              try {
                method.addInterceptor(
                    "com.baidu.oped.apm.plugin.user.interceptor.UserIncludeMethodInterceptor");
              } catch (Exception e) {
                if (logger.isWarnEnabled()) {
                  logger.warn("Unsupported method " + method, e);
                }
              }
            }

            return target.toBytecode();
          }
        });
  }