views:

103

answers:

3

I have a CPU intensive multi-threaded Java application and I'm looking for ways to measure its performance at run time (useful for automation). I tried a few options

System.currentTimeMillis();
System.nanoTime();
ThreadMXBean.getThreadCPUTime();

The first two measure real time. The last measures CPU time for only one thread. I want to measure the CPU-time for all threads spawned by the process.

Before resurrecting an old machine and dedicate it for this task, I would like to see what options I have now.

I run Linux and a platform dependent solution is acceptable, but least desirable.

+7  A: 

Try perf4j: http://perf4j.codehaus.org/ I recommend using it along with AOP, but it's not a must. See http://perf4j.codehaus.org/devguide.html#Using_Spring_AOP_to_Integrate_Timing_Aspects for more details on AOP.

Eran Harel
I'm pretty sure perf4j measures the realtime and not the CPU-time. I like the graphs though.
Alexandru
@Alexandru I believe this was the requirements. At least this is what I understand from the question...
Eran Harel
You are right, I was not clear enough. The problem with realtime is that running times changes if I browse StackOverflow
Alexandru
LOL @Alexandru. No performance testing while you surf the net. At least not if you're using the same machine ;)
Eran Harel
+1  A: 

Try to enable the JVM with Dtrace. It has a lot of performance probes which help you get what ever you want.

gaurav
Isn't Dtrace available only under Solaris?
Alexandru
Dtrace is available for openSolaris as well as Freebsd.One thing can be done is to get the java application on either of the OS just to do a performance of it and get the numbers.
gaurav
Dtrace is also available on Mac OS X. But the Dtrace probes enabled in the Mac OS X JVM may differ from those enabled for Solaris.
mattbh
+1  A: 

Take a look at the source of this plugin - JTop : http://blogs.sun.com/alanb/entry/two_fine_demos

Seven Seconds Mengesha