I'm searching for a 'something' that can measure the execution time if my java code. I know I can do that with intensive use of System.nanoTime() and things like that, but I need something more advanced.
Here what I want to do
gate.start("request");
gate.start("dbstuff");
doDbStuff();
gate.stop("dbstuff");
gate.start("businesslogic");
doSomeSimpleStuff();
for (int i = 0; i < 100; i++) {
gate.start("complexeAlgorithm"); // sum the 100 cycles
doComplexeAlgorithm();
gate.stop("complexeAlgorithm");
}
gate.stop("businesslogic");
gate.stop("request");
The output should be something like this
request 3.000 ms
+ dbstuff 700 ms
+ businesslogic 2.100 ms
+ complexeAlgorithm 300 ms
+ rest 1.800 ms
+ rest 200 ms
That 'something' may be a framework or a JVM tool or anything, that helps me to find my performance killers. Any suggestions?
You're asking for a profiler, the simplest one is free: have a look at jvisualvm, it comes with the java SDK. Another options are Yourkit and jprofiler.
Profiling is not an easy topic, so it would be better if you search "java profiler" in the web.