Mercurial > repos > rhope
view procprofile.py @ 156:ed70399a07aa
Add Substring method to string and improve performance of Partition
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 23 Dec 2010 02:00:27 +0000 |
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