Skip to content

Instantly share code, notes, and snippets.

@jld
Created April 5, 2013 21:23
Show Gist options
  • Save jld/5322730 to your computer and use it in GitHub Desktop.
Save jld/5322730 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import json, sys
prof = json.load(sys.stdin)
for thread in prof['profileJSON']['threads']:
raw = thread['samples']
low = [raw[i]['time'] - raw[i-1]['time'] for i in xrange(1, len(raw))]
while True:
oldlen = len(low)
avg = sum(low) / oldlen
low = [s for s in low if s < 2 * avg]
if len(low) == oldlen:
break
print >>sys.stderr, "Estimated sample tick %g ms" % avg
padded = []
last = raw[0]['time']
for sample in raw:
n = int((sample['time'] - last) / avg)
padded += [sample] * max(n, 1)
last = sample['time']
thread['samples'] = padded
json.dump(prof, sys.stdout, separators=(",",":"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment