简体   繁体   English

对核心Java进行性能分析,以检查每个计数器处的方法统计信息和延迟

[英]Profiling core java to check method statistics and latency at every counter

//method 1 & 2 contain calls to a number of other methods
for(int i=0; i<100;i++) {
    method1();
    method2();
}

I'd like to profile the above java code at every counter 'i' of the loop, and get method statistics (specifically the execution latency) at each value of i. 我想在循环的每个计数器“ i”处剖析上述java代码,并在i的每个值处获取方法统计信息(特别是执行延迟)。

The methods method1() and method2() contain calls to other methods, including method calls from their dependencies. 方法method1()和method2()包含对其他方法的调用,包括来自其依赖项的方法调用。

How can I profile my code at each counter? 如何在每个柜台配置我的代码? I don't think it's possible with JProfiler. 我认为JProfiler无法实现。

In JProfiler this is possible with method splitting . 在JProfiler中,可以通过splitting方法实现 First of all, you should wrap your calls to method1 and method2 into another method and pass i as a parameter: 首先,您应该method1method2调用包装到另一个方法中,并将i作为参数传递:

...

for(int i=0; i<100;i++) {
   measure(i);
}

...

void measure(int i) {
   method1();
   method2();
}

Then profile your code, go to the call tree, select the measure method and choose Split Method With a Script from the context menu. 然后分析您的代码,转到调用树,选择measure方法,然后从上下文菜单中选择“ Split Method With a Script In the script dialog that is now displayed, configure String.valueOf(i) as the script. 在现在显示的脚本对话框中,将String.valueOf(i)配置为脚本。 For the next profiling run, you will now get the slowest executions of measure separately in the call tree. 对于下一次性能分析运行,您现在将在调用树中分别获得最慢的measure执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM