Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

itstack-demo-agent-02-MyMonitorTransformer #3

Open
ToTouchMyheart opened this issue May 21, 2021 · 0 comments
Open

itstack-demo-agent-02-MyMonitorTransformer #3

ToTouchMyheart opened this issue May 21, 2021 · 0 comments

Comments

@ToTouchMyheart
Copy link

enhanceMethod方法中的字节码增强建议修改为CtBehavior.insert*方法 。 之前那种方式在增强方法中有调用其他类方法时,可能会有问题
// 前置增强: 打入时间戳
method.addLocalVariable("start", CtClass.longType);
method.insertBefore("start = System.nanoTime();");
final StringBuilder source = new StringBuilder();
// 保留原有的代码处理逻辑
// 后置增强,计算输出方法执行耗时
source
.append("System.out.print("method:[")
.append(methodName).append("]");").append("\n")
.append("System.out.println(" cost:[" +(System.nanoTime() - start)+ "ns]");")
;
method.insertAfter(source.toString());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant