HPROF in java(part-1)

12 Oct

HPROF is a heap/cpu profiling tool.By supplying HPROF options at startup, we can request various types of heap and/or cpu profiling features from HPROF. The data generated can be in textual or binary format, and can be used to track down and isolate performance problems involving memory usage and inefficient code.

java –Xrunhprof:heap=sites,cpu=samples,depth=10,monitor=y,thread=y,doe=y sample

(sample- program name)

another way

java -agentlib:hprof[=options] sample

The output file is created in the current directory and is named java.hprof.txt.

To get more information about option in hprof use this

java -agentlib:hprof=help

java.hprof.txt file contain many sections

SITES BEGIN (ordered by live bytes) Thu Jul 18 11:23:06 2002
          percent         live       alloc'ed  stack class
 rank   self  accum    bytes objs   bytes objs trace name
    1 59.10% 59.10%   573488    3  573488    3   668 java.lang.Object
    2  7.41% 66.50%    71880  543   72624  559     1 [C
    3  7.39% 73.89%    71728    3   82000   10   649 java.lang.Object
    4  5.14% 79.03%    49896  232   49896  232     1 [B
    5  2.53% 81.57%    24592  310   24592  310     1 [S

the above thing is sample of site section.The SITES section shows memory allocation sites. The section has several rows, sorted by the number of bytes that are allocated and are being referenced—the live bytes. The memory is listed in bytes. The column self represents the percentage of memory taken up by this site, the next column, accum, represents the cumulative memory percentage. Thelive bytes and live objects columns represent the number of live bytes at this site and the number of objects that were created that consumes these bytes. The allocated bytes and objects represent the total number of objects and bytes that are instantiated, including the ones being used and the ones not being used. The difference in the number of bytes listed in allocated and live represent the bytes that can be garbage collected.  The trace column actually references a TRACE in the file. The first row references trace 668 as shown below. The name represents the class whose instance was created.

TRACE 668: (thread=1)

This trace shows the method call sequence that allocates the memory.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: