I need to measure performances on a specific part of my application.
To calculate these measures, I use the Spring StopWatch
class.
In a method, there is a loop where I need to measure the execution of each iteration.
What I would like is to have, for the loop part, a counter, and the min / max / average values.
Unfortunately, Spring StopWatch
class does not provides such feature.
For example, the following code:
StopWatch watch = new StopWatch("foo");
watch.start("First process");
doSomething();
watch.stop();
for (int i = 0; i < 10; i++) {
watch.start("loop");
doAnotherThing();
watch.stop();
}
System.out.println(watch.prettyPrint());
will output:
StopWatch 'foo': running time (millis) = 1469
-----------------------------------------
ms % Task name
-----------------------------------------
01000 068% First process
00078 005% loop
00000 000% loop
00016 001% loop
00047 003% loop
00015 001% loop
00047 003% loop
00094 006% loop
00000 000% loop
00109 007% loop
00063 004% loop
What I want is to have:
StopWatch 'foo': running time (millis) = 1469
-----------------------------------------
ms % Task name
-----------------------------------------
01000 068% First process
00469 032% loop | min: 0 ; max: 109 ; average: 47 ; count: 10
Is there a way to achieve that using Spring?
ps: I know that perf4j will allow that, but if I can avoid adding a new library, it would be great...