In the method to be instrumented inlet, outlet corresponding logical add

rivate class TraceMethodAdapter extends AdviceAdapter {

private final String methodName;
private final String name;
private final String className;
private final boolean hasWindowFocusMethod;
private final boolean isMethodBeatClass;

protected TraceMethodAdapter(int api, MethodVisitor mv, int access, String name, String desc, String className,
boolean hasWindowFocusMethod, boolean isMethodBeatClass) {
super(api, mv, access, name, desc);
TraceMethod traceMethod = TraceMethod.create(0, access, className, name, desc);
this.methodName = traceMethod.getMethodName();
this.isMethodBeatClass = isMethodBeatClass;
this.hasWindowFocusMethod = hasWindowFocusMethod;
className = this.className;
this.name = name;
}

@Override
protected void onMethodEnter () {
TraceMethod traceMethod = mCollectedMethodMap.get (methodName);
IF (! traceMethod = null) {
// add logic function entry;
// No separate treatment onWindowFocusChange, to have replication onWindowFocusChange the Activity subclass, there will be problems?
traceMethodCount.incrementAndGet ();
mv.visitLdcInsn (traceMethod.id);
mv.visitMethodInsn (invokestatic, TraceBuildConstants.MATRIX_TRACE_CLASS, "i", "(the i) V ", to false);
}
}

@Override
protected void onMethodExit (int of opcode) {
traceMethod traceMethod = mCollectedMethodMap.get (methodName);
! IF (traceMethod = null) {
if (hasWindowFocusMethod && mTraceConfig.isActivityOrSubClass(className, mCollectedClassExtendMap)
&& mCollectedMethodMap.containsKey(traceMethod.getMethodName())) {
TraceMethod windowFocusChangeMethod = TraceMethod.create(-1, Opcodes.ACC_PUBLIC, className,
TraceBuildConstants.MATRIX_TRACE_ON_WINDOW_FOCUS_METHOD, TraceBuildConstants.MATRIX_TRACE_ON_WINDOW_FOCUS_METHOD_ARGS);
if (windowFocusChangeMethod.equals(traceMethod)) {
//onWindowFocusChange方法统一添加method id = -1的逻辑
traceWindowFocusChangeMethod(mv);
}
}
//函数出口处添加逻辑
traceMethodCount.incrementAndGet();
mv.visitLdcInsn(traceMethod.id);
mv.visitMethodInsn(INVOKESTATIC, TraceBuildConstants.MATRIX_TRACE_CLASS, "o", "(I)V", false);
}
}
}

Guess you like

Origin www.cnblogs.com/liyanyan665/p/11291199.html