For analysis of the Java heap, add the following option to your Java command line.
-Xrunhprof:heap=sites
Other options are “heap=dump” and “heap=all”.
Run Java, and then when your program completes, look for the “java.hprof.txt” inside the folder you started Java. The contents of that file depends on which option you choose. The “sites” option is particularly useful when you want to look for a memory leak. Run your program, ending with a System.gc (). Then look in the output to see if there are unexpected objects still being held onto. It’s also useful if you think you are generating lots of temporary objects and spending a lot of time in garbage collection.
For analysis of cpu time, there are HPROF options to sample cpu time and to do more precise timing. It is best to start with cpu samples because there is not much overhead to running your program that way.
-Xrunhprof:cpu=samples
-Xrunhprof:cpu=times
Information about the HPROF profiler can be found at the following locations:
- http://java.sun.com/developer/technicalArticles/Programming/HPROF.html
- http://java.sun.com/developer/onlineTraining/Programming/JDCBook/perf3.html#analysis
Garbage Collection Information
If you want to study garbage collection performance, there are more options you can add to your Java command line:
-verbose:gc -Xloggc:gc.out -XX:+PrintGCDetails
See also:

Recent Comments