Profiling is an excellent way to find resource bottlenecks in a program. Java has built-in profiling tools that you can use to easily view a profile of a program’s runtime execution.
To generate a profiling report for a Java program, add the hprof profiler to the program’s command line as follows.
java -Xrunhprof:cpu=samples,depth=30,file=myprogram.hprof other arguments...
When the program terminates, it writes a profile report to myprogram.hprof. JDC Tech Tips has an article on Using HPROF to Tune Performance [Wayback Machine link, as the original link is broken], which explains the format of the profile file. But you’ll probably want to skip straight ahead to using a GUI program to view the file, so…
There is a free tool with the unfortunate name of PerfAnal that analyses profile files and presents them using a graphical interface. PerfAnal: A Performance Analysis Tool on Sun Oracle’s Java site contains instructions and a link to download the tool. A few minutes’ tinkering with this can yield valuable insights into the workings of a program.
Neat way of finding the rogue methods. The tool was really helpful.
link seems broken?
@roger, the link is indeed broken. I have fixed it to point to the Wayback Machine version instead.
Thnkx for the info. Helped me at lot…
Ther “PerfAnal” link should now ( sun -> oracle ) rather go to
http://www.oracle.com/technetwork/articles/javase/perfanal-137231.html
Thanks @Michael — I have updated the link.