Create a gist now

Instantly share code, notes, and snippets.

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment