HPROF is a simple profiler agent shipped with the Java™ 2 SDK. It is a dynamically linked library that interacts with the JVMPI (Java™ Virtual Machine Profiler Interface) and writes out profiling information either to a file or to a socket in ASCII or binary format. This information can be further processed by a profiler front-end tool such as HAT.
HPROF can present CPU usage, heap allocation statistics, and monitor contention profiles. In addition, it can also report complete heap dumps and states of all of the monitors and threads in the Java virtual machine. For more details on the HPROF profiler, see the JDK documentation at:
Once HPROF is installed using the following instructions, its libraries are loaded into the server process.
Configure Sun Java System Web Server in one of these ways:
Classpath: (leave blank)
Native Lib Path: (leave blank)
JVM Option: For each of these options, type the option in the JVM Option field, select Add, then check its box in the JVM Options list:
<!-- hprof options --> <PROFILER name="hprof" enabled="true"> <JVMOPTIONS> -Xrunhprof:file=log.txt,options </JVMOPTIONS> </PROFILER>
Do not use the -Xrs flag.
Here is an example of options that you can use:
The file option is important because it determines where the stack dump is written in step 6.
The syntax of HPROF options is as follows:
Using help lists options that can be passed to HPROF. The output is as follows:
Hprof usage: -Xrunhprof[:help]|[:<option>=<value>, ...] Option Name and Value Description Default --------------------- ----------- ------- heap=dump|sites|all heap profiling all cpu=samples|old CPU usage off format=a|b ascii or binary output a file=<file> write data to file java.hprof (.txt for ascii) net=<host>:<port> send data over a socket write to file depth=<size> stack trace depth 4 cutoff=<value> output cutoff point 0.0001 lineno=y|n line number in traces? y thread=y|n thread in traces? n doe=y|n dump on exit? y
You must also change a line in the Sun Java System Web Server start script. The start script file is instance_dir/start. Change the following line:
Start the server by running the start script. Since the server runs in the foreground (the change in step 2), the command prompt returns only after the server is stopped.
In another window or terminal, find the process ID of the server process.
% ps -ef | grep webservd
This command lists two webservd processes. Look at the PPID (parent process ID) column and identify which of the two processes is the parent process and which is the child process. Note the PID (process ID) of the child process ID.
Send a SIGQUIT signal (signal 3) to the child process:
% kill -QUIT child_PID
To stop the Web Server, run the stop script from another window.
This writes an HPROF stack dump to the file you specified using the file HPROF option in step 1. For general information about using a stack dump, see Generating a Stack Trace for Debugging
To return your Web Server to its original configuration, undo the changes in steps 1 and 2.