I have a fairly complex Java application that is utilizing a lot of CPU, and would like to know if there is any recommendation on a profile tool that I could use to determine the cause of the CPU utilization. My goal is to pinpoint the location in the code where it is using most of the CPU time.
-
Any Java profiler will run on Linux.Dolph– Dolph2010-03-05 16:29:26 +00:00Commented Mar 5, 2010 at 16:29
-
Are you using an IDE? Most good IDEs have profilers either built in or available as modules.Michael Myers– Michael Myers ♦2010-03-05 16:29:36 +00:00Commented Mar 5, 2010 at 16:29
-
Nope, I am not running an IDE. My application actually is started my another application.beyonddc– beyonddc2010-03-05 16:32:48 +00:00Commented Mar 5, 2010 at 16:32
-
What Java version are you running? Is it 1.6 update 7 or newer?Michael Myers– Michael Myers ♦2010-03-05 16:34:41 +00:00Commented Mar 5, 2010 at 16:34
-
1If you have JDK 1.6.0_07 or newer, it comes with JVisualVM; that's why I ask.Michael Myers– Michael Myers ♦2010-03-05 17:43:00 +00:00Commented Mar 5, 2010 at 17:43
6 Answers
I've used jProfiler and YourKit on Linux. But you might find the information you're looking for by running the jconsole that comes with recent JDKs. Good information on how to use it: http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html
Comments
Netbeans has good built-in profiler. NB runs quite well on Ubuntu 9.10
If your issue cannot be observed in developement, you can attach the profiler to a remote JVM (your production environment). You have to configure the host JVM to accept the JMS/JConsole connections from the profilers. The JMS/JConsole realtime monitoring visualization charts look pretty awesome.
Comments
This method is low-tech but works best. Here's a short explanation why.
Since you are not running under an IDE, you can use pstack or lsstack to get stack samples. If the app is using lots more time than it should, then most likely the problem is one or a few rogue function calls, which will be clearly visible on most of the stack samples.