简体   繁体   中英

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.

The methods method1() and method2() contain calls to other methods, including method calls from their dependencies.

How can I profile my code at each counter? I don't think it's possible with JProfiler.

In JProfiler this is possible with method splitting . First of all, you should wrap your calls to method1 and method2 into another method and pass i as a parameter:

...

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. In the script dialog that is now displayed, configure String.valueOf(i) as the script. For the next profiling run, you will now get the slowest executions of measure separately in the call tree.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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