Created
June 24, 2015 06:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__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) | |
good that someone finds it useful.
+1
thanks for sharing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good idea.
I have added few more features to this one and reimplemented.
https://github.com/Rachangouda/utils