q-text-as-data to create histogram from java heap dump

When java heap is used by many java.lang.String or “Class [C”  , it is often difficult to get a high level picture. Below is a screen capture of firefox browser accessing ‘jhat’ .   I thought I would create histogram for numbers in red rectanble. i.e.) (NNNNNN bytes).

From quick browsing of this page, I knew that largest number is 2.3MB. So I decided to bin(bucket) every 10000 bytes and show sum().

image

There may be many ways to this. I used #qtextasdata.

$ curl --silent http://localhost:8001/class/0x703af77a8 |
  sed -rn 's/^<a .* \(([0-9]+) bytes\).*$/\1/p'  |
  sort -n|uniq -c |
  q 'select sum(c1*c2),c2/10000 from - group by c2/10000'
162529307 0
388236 1
158056 2
269652 3
[... continue ...]

Above doesn’t fill the vacant bin with ‘0’ but I think this is good enough to know the distribution and find memory leak suspects.

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