See also: Heapify

Back to doug's directory

File information
Filename: parse-gc-histogram.py Uploaded: Sat, 15th Jan 2011 01:19:24
Size (bytes): 976 bytes md5 checksum: ad9e009a262abe4a614afcfb9adc190a
Uploader doug Download: parse-gc-histogram.py
Description:

Referred by Detecting, locating and fixing memory leaks (Java)

A little script to get a delta between two formatted histograms produced by the JDK command: jmap -histo

Author: doug@neverfear.org Date: 2011-01-10 Usage: python parse-gc-histogram.py HISTOGRAMFILE1 HISTOGRAMFILE2

#!/usr/bin/python
 
import sys
 
'''
A little script to get a delta between two formatted histograms produced by the JDK command: jmap -histo
Author: doug@neverfear.org
Date: 2011-01-10
Usage: python parse-gc-histogram.py HISTOGRAMFILE1 HISTOGRAMFILE2
'''
 
def ParseHisto(filename):
	f = open(filename, "r")
	histo = {}
	for i, line in enumerate(f):
		columns = line.split()
		if len(columns) == 4:
			num, instances, bytes, classname = columns
			histo[classname] = long(instances)
	return histo
 
def DeltaDict(a, b):
	delta = {}
	for k, v in a.items():
		if k not in b:
			bv = 0
		else:
			bv = b[k]
		delta[k] = bv - v
	return delta
 
if __name__ == "__main__":
	histo1 = ParseHisto(sys.argv[1])
	histo2 = ParseHisto(sys.argv[2])
	delta = DeltaDict(histo1, histo2)
	sorted = [(v, k) for k, v in delta.items()]
	sorted.sort(reverse = True)
 
	print "% 20s %s" % ("Num", "Class")
	for v, k in sorted:
		print "% 20d %s" % (v, k)
	print
RSS
Powered by Debian, Guinness, and excessive quantities of caffeine and sugar.