Skip to content

Instantly share code, notes, and snippets.

@int3
Created July 20, 2011 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save int3/1094145 to your computer and use it in GitHub Desktop.
Save int3/1094145 to your computer and use it in GitHub Desktop.
Postprocess chrome->content analysis output
#! /usr/bin/env python
"""
Usage: python postprocess.py [logfile] [src files we're interested in] > out.html
Incl.: offending calls from callee get added to the caller's count
Excl.: offending calls from callee do not get added to the caller's count
"""
import sys, re
from collections import defaultdict
data = open(sys.argv[1]).read()
class Counter:
def __init__(self):
self.incl = 0
self.excl = 0
self.propnames = set()
self.callees = set()
funcs = defaultdict(Counter)
flist = sys.argv[2:]
for para in data.split("\n\n"):
lines = para.split("\n")
callee = ""
for line in lines:
match = re.match("(\d+) (.*) \[(.*):\d+]", line)
if not match:
if line[0:9] == 'property:':
propname = line[10:]
continue
depth = int(match.group(1))
func_name = match.group(2)
file_name = match.group(3)
callee = func_name
if flist != []:
for f in flist:
if f in file_name:
break
else:
continue
funcs[func_name].incl += 1
if depth == 0:
funcs[func_name].excl += 1
if propname != "":
funcs[func_name].propnames.add(propname)
else: # callee != ""
funcs[func_name].callees.add(callee)
print "<table border=1>"
print "<tr><th>Name</th><th>Incl.</th><th>Excl.</th></tr>"
for name, counter in sorted(funcs.items(), key=lambda x:x[1].excl, reverse=True):
print "<tr title='" + ", ".join(counter.propnames | counter.callees) + "'><td>" + "</td><td>".join([name, str(counter.incl), str(counter.excl)]) + "</td></tr>"
print "</table>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment