For analysis of the Java heap, add the following option to your Java command line.
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.
Information about the HPROF profiler can be found at the following locations:
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