view procprofile.py @ 189:d0e3a13c1bd9 default tip

Remove old calculator example
author Mike Pavone <pavone@retrodev.com>
date Fri, 07 Oct 2011 00:24:04 -0700
parents 60906f8803ef
children
line wrap: on
line source

#!/usr/bin/env python

def unescapename(name):
	trans = {"UN":'_',"AT":'@',"SP":' ',"QN":'?',"PL":'+',"MN":'-',"TM":'*',"DV":'/',"LT":'<',"GT":'>',"NT":'!',"EQ":'=',"PR":"'"}
	out = ''
	while (name):
		before,_,name = name.partition('_')
		if name:
			out += before[:-2]
			key = before[-2:]
			if key in trans:
				out += trans[key]
			else:
				out += key+_
		else:
			out += before
	return out.replace('__', '_')
		

names = [unescapename(line.strip()) for line in open('workernames.txt', 'r')]
records = []

data = open('profiler.txt', 'r')

for line in data:
	funcid,_,rest = line[len('Func: '):].partition('\tCount: ')
	count,_,rest = rest.partition('\tTime: ')
	total,_,rest = rest.partition('\tAvg: ')
	avg,_,rest = rest.partition('\tSelf: ')
	self,_,rest = rest.partition('\tAvg: ')
	selfavg,_,nestcount = rest.partition('\tNested Count: ')
	records.append((names[int(funcid)], int(count), int(total), float(avg), int(self), float(selfavg), int(nestcount)))
	
	
records.sort(key=lambda el: el[3])

print 'Func\tCount\tTotal(us)\tAvg(us)\tSelf(us)\tSelf Avg(us)'
for record in records:	
	print '%s\t%d\t%d\t%f\t%d\t%f\t%d' % record