Skip to content

Instantly share code, notes, and snippets.

@insom insom/
Last active Dec 24, 2015

What would you like to do?
Parse a PHP-format callgrind file and produce a summary of what time was spent in what files.
import re
import sys
states = ('DEFAULT', 'HAVE_FILE')
fl = re.compile('^fl=(.*)')
num = re.compile('^\d+ (\d+)')
state = 0
current_file = ''
inclusive = False
f = file(sys.argv[1], 'r')
d = dict()
for line in f.xreadlines():
line = line.strip()
x =
if not 'modman' in x.groups(1)[0]:
current_file = x.groups(1)[0]
current_file = re.sub('.*modman/', '', current_file)
current_file = current_file.split('/')[0]
state = 1
if state == 1:
x =
i = d.get(current_file, 0) + int(x.groups(1)[0])
d[current_file] = i
if not inclusive:
state = 0
x = [(v, k) for k, v in d.items()]
for v, k in x:
print v, k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.