Profiling a Java program easily

Sunday, 18 April 2004

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.

Tags: ,


You can leave a comment, or trackback from your own site.

  1. vinay chilakamarri

    Neat way of finding the rogue methods. The tool was really helpful.

  2. link seems broken?

  3. @roger, the link is indeed broken. I have fixed it to point to the Wayback Machine version instead.

  4. Thnkx for the info. Helped me at lot…

  5. Ther “PerfAnal” link should now ( sun -> oracle ) rather go to

  6. Thanks @Michael — I have updated the link.

Leave a comment