Skip to content

Instantly share code, notes, and snippets.

@primiano
Last active January 22, 2016 10:29
Show Gist options
  • Save primiano/dbbdaf927e0b08c21bc2 to your computer and use it in GitHub Desktop.
Save primiano/dbbdaf927e0b08c21bc2 to your computer and use it in GitHub Desktop.
import collections
import json
import gzip
import sys
TOPN = 15
def print_hist(hist, evt_count, top=TOPN):
for key, count in sorted(hist.iteritems(), key=lambda x:x[1], reverse=True):
print ' %-32s %6d %.2f %%' % (key, count, 100.0 * count / evt_count)
top -= 1
if top == 0:
break
def main():
with gzip.GzipFile(sys.argv[1]) as gzf:
trace = json.load(gzf)
evt_count = len(trace['traceEvents'])
hist_cat = collections.defaultdict(int)
hist_evt = collections.defaultdict(int)
for evt in trace['traceEvents']:
hist_cat[evt['cat']] += 1
key = '%-12s - %-60s' % (evt['cat'], evt['name'])
hist_evt[key] += 1
print 'Total trace events: %d' % evt_count
print '\nHistogram by category (top %d)' % TOPN
print_hist(hist_cat, evt_count)
print '\nHistogram by event (top %d)' % TOPN
print_hist(hist_evt, evt_count)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment