문제

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.

다른 팁

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/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top