3.Start the profiling interval: send a signal to the JVM by typing: kill -USR2 pid

You will see the following message: eprof: starting profiling

Let the profiling collection generated by the JVM continue for the length of time that you think will be meaningful.

4.Stop the profiling interval by sending the same signal to the JVM: kill -USR2 pid

You will see the following message: eprof: terminating profilingwriting profile data to ./filename.eprof

You can now open the saved file in the HPjmeter console and view the collected metrics.

NOTE: For the signal to be captured by the JVM, you must either be logged in as root, or you must be the user who started the JVM.

Related Topics

Zero Preparation Profiling (page 195)

Profiling with -agentlib:hprof

Java 2 introduced a profiling interface, called JVMPI (Java Virtual Machine Profiler Interface). This interface came with a sample profiling agent, called hprof.

The Java 5.0 release introduced an improved profiling interface, called JVMTI (Java Virtual Machine Tool Interface), which replaces JVMPI. The hprof agent is also available with JVMTI.

This agent creates profile data files that can be interpreted after the program terminates. However, note that the format of the files may be still evolving. Most Java versions based on JavaSoft implementations are compatible. Currently HPjmeter can read text and binary files.

To run your application with profiling, use the following command:

$ java ... -agentlib:hprof[=options] ApplicationClassName

To profile an applet, use the following command:

$ appletviewer ... -J-agentlib:hprof[=options] URL

The following options are useful:

For performance profiling: cpu=samples,thread=y,depth=10,cutoff=0,format=a

If you must have method call counts for performance profiling: cpu=times,thread=y,cutoff=0,format=a

For analyzing object allocations: heap=sites,cpu=samples,thread=y,cutoff=0,format=a

For solving memory retention problems ("memory leaks"): heap=all,thread=y,cutoff=0,format=a,doe=n

Then use kill -QUITpid (on UNIX ) to get the heap dump.

NOTE: Beginning with HPjmeter version 3.1, you can view binary hprof files (format=b) in HPjmeter visualizers.

To see the complete list of available options, usejava ... -agentlib:hprof=help

Collecting Profile Data

63