Skip to content

Instantly share code, notes, and snippets.

@alexcpn
Created June 24, 2015 06:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexcpn/a68761c94c85f0210413 to your computer and use it in GitHub Desktop.
Save alexcpn/a68761c94c85f0210413 to your computer and use it in GitHub Desktop.
Here is a script to compare two jmap class histogram dumps, to see which classes are increasing memory. This can be used as a rough tool in checking suspect classes while analyzing Java memory leaks, as dumping large heaps and analyzing the same can be hard
__author__ = 'acp'
import re
import fileinput
import operator
import sys
objectschanged={}
def create_object_list(line2,mapofObjects,instance):
container = line2.split()
#print(container)
if container[3] in mapofObjects:
val=mapofObjects[container[3]]
#print(container[3],"difference=",abs(int(container[2])-val))
objectschanged[container[3]]=(int(container[instance])-val)
else:
mapofObjects[container[3]]=int(container[instance])
#Call the main function
print("A Python Script to parse the Jmap generated Histograms ")
print("Author - Alex.Punnen")
print("Usage- jmaphistoparser.py filename1 filename2")
#print ("Where M is the difference in memory and I difference in isntance and fo")
instance=1 #for instance difference
#instance=2 #for memeory difference
mapofObjects={}
content=[]
for line in fileinput.input():
content.append(line)
count=0
#skip lines
while len(content) >0 :
line=content.pop()
if(':' in line):
count+=1
create_object_list(line,mapofObjects,instance)
print("------------------------Objects Changed Between Heaps-------------------------------------------")
sorted_x = sorted(objectschanged.items(), key=operator.itemgetter(1))
for(x,y) in sorted_x:
print(x,y)
@Rachangouda
Copy link

Good idea.
I have added few more features to this one and reimplemented.
https://github.com/Rachangouda/utils

@alexcpn
Copy link
Author

alexcpn commented Aug 16, 2019

good that someone finds it useful.

@MarcelFadtke
Copy link

+1
thanks for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment