JIP — The Java Interactive Profiler
hproftool that ships with the JDK. There are, however, a few differences:
hprofis not an interactive profiler. It starts when your program starts and ends when the JVM exits. In many cases this doesn't give you a true measure of performance since the Just In Time compiler doesn't compile code on the first pass. In addition, this type of profiler is not useable at all in web applications since you end up profiling the web container as well as the web application. JIP, on the other hand, allows you to turn the profiler on and off while the JVM is running.
JVMPI(Java Virtual Machine Profiling Interface) which requires the use of native components. JIP, however, is pure Java. It takes advantage of the Java5 feature which allows you to hook the classloader. JIP adds aspects to every method of every class that you want to profile. These aspects allow it to capture performance data.
hprofwill cause a program to run 20 times slower. JIP, on the other hand, is lightweight. A VM with profiling turned on is about twice as slow as one without a profiler. When the profiler is turned off, there is almost no overhead associated with using JIP.
hprof, for example, will show you the relative amount of time that is spent in different parts of your code, but
hprofhas so much overhead, that you cannot use it to get real world timing measurements. JIP, on the other hand, actually tracks the amount of time used to gather performance data and factors that time out of its analysis. This allows you to get close to real world timings for every class in your code. So there is no need to litter your code with
To run the profiler, you need the following:
These files are loaded by the application classloader and should not be in the extentions loader path. The jar files need to be in the same directory. The properties file can be anywhere.
To use the profiler, you need to use the following JVM arguments:
where [DIR] is the directory that contains the profile.jar
Note: Due to a bug in the JDK on OS X, [DIR] must be a fully qualifed path.and [DIR2] is the directory that contains the profile.properties
By default (if you don't give a
profiling starts out turned on and the remote
interface (use to profile interactively) is turned off (see
profile.properies for more information). In
this case JIP works just like
hprof, although it is
When using with stock Tomcat, set the java agent by using the
JAVA_OPTS. For example, on Windows
use the following:
Where [DIR1] and [DIR2] are described as above.
SET JAVA_OPTS=-javaagent:[DIR]\profile.jar -Dprofile.properties=[DIR2]\profile.properties
In some cases, like webapps, you probably want to start out with the profiler turned off. When you get to some case you want to test, you'd like to turn it on, run the test case, turn the profiler off and dump the results. To do these things, you first of all need to change the profile properties file:
To interact with the profiler you need the
profiler=off remote=on port=15599
client.jarwhich is in the
/clientdirectory of the JIP distribution.
File.bat localhost 15599 c:\tmp\test-profile.txt
Start.bat localhost 15599
Finish.bat localhost 15599
example.sh. All use the example of compiling JIP with ant.
example-ant-1.5.shwork only with ant 1.5 and
example.shworks only with ant 1.6 (this is because the way that ant gets invoked changed between the two releases).