To invoke profiling, include the following option in your JVM:
    -Xrunhprof:cpu=samples,depth=3
(this may require an additional 32Meg or so).

After running your program, additional info will be placed in a file called java.hprof.txt. To be specific, the option above instructs the virtual machine to periodically examine (ie. sample) the stack trace to figure out what method it is in (and how it got there). The theory is that if it has examined the stack trace 1000 times, and 500 times it finds it is in method foo, called from bar, it is reasonable to assume that 50% of the running time of the program is spent there. (This theory also tells you that for very short running programs, there might not be enough sampling to get an accurate estimation.) The raw file java.hprof.txt, however, is not in an easy to read format for humans. There is a program that is available on the internet that processes the raw file, and generates an image showing the frequently occuring calls. This is the performance analyzer.

Download PerfAnal.jar and place it on your CLASSPATH Remember that if you have not ever set your CLASSPATH, you will also need to place . (current directory) on your CLASSPATH. You can do this in the system environment dialog for Windows systems. (note: as an alternative, if you can put the jar file in the jre\lib\ext folder for your system, that would be preferable to messing up the CLASSPATH) Once the jar file is visible, you can then invoke the analyzer with

java com.macmillan.nmeyers.PerfAnal java.hprof.txt