Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

look at https://github.com/codahale/metrics

Metrics is a Java library which gives you unparalleled insight into what your code does in production. Metrics provides a powerful toolkit of ways to measure the behavior of critical components in your production environment.

With modules for common libraries like Jetty, Logback, Log4j, Apache HttpClient, Ehcache, JDBI, Jersey and reporting backends like Ganglia and Graphite, Metrics provides you with full-stack visibility.

http://metrics.codahale.com/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top