by Ulf Dittmer and Greg White
This Java application reads profiling information produced by the Java interpreter and various flavours of the gprof tool and displays it for easy interpretation.
ProfileViewer was originally written by Greg White.
Now that he no longer maintains it, he has released the source
under the GNU General Public License. This page describes the changes that
have been made since then; please do not contact Greg about this version.
These instructions accompany version 1.0 of ProfileViewer. See the COPYING file for copyright and license information.
Requirements: Java 1.4 or later
Although PV was conceived to handle the profiling output of Java 1, it works fine with the
output generated by Java 2 if the "-prof" option is used (instead of the "-Xrunhprof" option,
which generates Java 2 profiling output.)
For Java 2 either the "-Xrunhprof:cpu=old" or the "-classic -prof" switch can be used,
neither of which worked without hiccups for me, but your mileage may vary.
I have no plans to add support for the Java 2 format to PV; the file format is
very different. I'd be happy to integrate it if someone wants to take a shot
at it, though. Thanks to enhancements by Luc Maisonobe, several different
profiling formats can be recognized and read by PV.
Download
Latest version 1.0.3 released June 16, 2009
This Zip file contains the source files, the executable jar file and the documentation.
-prof
option (e.g. java -prof MyApp
).
The procedure for creating a profile file for an applet is similar. Type
java -prof sun.applet.AppletViewer
app.html
where app.html is the HTML file you normally pass to the applet viewer. When profiling applets, you may find that there is much more profiling information than you really want due to all of the supporting classes.
java ProfileViewer
Profile
where Profile optionally specifies the name of a profile file to load. If this parameter is not specified, ProfileViewer will start without loading a file. This assumes all jar files are in your classpath. Alternatively, Windows users can simply double-click the "runit.bat" file.
It is also possible to double-click the ProfileViewer Jar file.
The format of each line in these lists is
time calls methodwhere time and calls are shown as percentages by default, but they can be changed to show absolute values (time in milliseconds and calls by count).
All percentages are relative to the lifetime of the application. In the methods list, the percentage is an overall value for each method. In the callees list, percentages shown reflect calls made to each method from the selected method to the left. In the callers list, percentages shown reflect calls made from each method to the selected method to the left.
When showing absolute values, the methods list entries are totals for each method while in the callees and callers list, these numbers are only in relation to the selected method in the list on the left.
The status line at the bottom shows the full name of the currently selected method. This helps you to see names that might be too long otherwise.
Entries of the form "...<init>"
indicate the constructor
of the respective class, those of the form "...<clinit>"
static initializers of the class.
Also note that Sun's documentation for javaprof (a text-based report tool for the profile file) says it will not work correctly for multi-threaded applications. I expect that this warning ought to be for the profile file itself, not just for javaprof.
gprof
utility. Gprof can convert the binary output generated while running
programs compiled by a C, C++, pascal or fortran compiler with the
-pg
profiling flag into a text format.gprof
utility. Gprof can convert the binary output generated while running
programs compiled by a C, C++, pascal or fortran compiler with the
-pg
profiling flag into a text format.-pg
flag.gcc -pg test.c
./a.out
gprof -b -z a.out > results.txt
java -jar ProfileViewer-1.0.3.jar results.txt
The first step is to create your own parser as a class implementing
the ProfileParser
interface. This interface is limited to
three methods: nextInvocationLine
,
stopParsing
and getLineNo
. The easiest way
to do this is to start from the existing classes
(ClassicJavaProfileParser
and
[Abstract|GNU|OSX|Solaris]GprofProfileParser
).
The second step is to register your class in the parser factory
method ProfileParserFactory.buildParser
. This step is
merely adding a two lines test in an existing if
statement.