analyze_profiling_output
author Alon Zakai <azakai@mozilla.com>
Wed, 30 May 2012 16:31:59 -0700
changeset 585 694acee4d0b4
parent 463 55888edc87b5
permissions -rw-r--r--
work
diff --git a/analyze_profiling_output.py b/analyze_profiling_output.py
new file mode 100644
--- /dev/null
+++ b/analyze_profiling_output.py
@@ -0,0 +1,53 @@
+import os, sys
+
+lines = open(sys.argv[1], 'r').readlines()
+
+stuff = {}
+
+for line in lines:
+  line = line.replace('\n', '').replace('\r', '')
+  if line == '': continue
+  if line[0] != '|': continue
+  line = line[1:]
+  try:
+    what, name, took_text, seconds, sec_text, main_text, eq_text, main_thread = line.split(' ')
+  except Exception, e:
+    print "Exc:", e, "in line:", line
+    continue
+  if what not in ['Runnable', 'Event', 'IPC', 'ChildAsyncIPC', 'ParentAsyncIPC', 'ParentSyncIPC']: print 'what?', what; continue
+  name = name.replace("'", '')
+  if name == 'DoWorkRunnable': name = '*** All IPC ***'
+  if name == 'RecvAsyncMessage': name = '*** Async mM IPC ***'
+  if name == 'RecvSyncMessage': name = '*** Sync mM IPC ***'
+  fullname = what + '|' + name + '|' + ('main' if main_thread == '1' else 'side')
+  stuff.setdefault(fullname, { 'name': fullname, 'total': 0, 'num': 0 })
+  stuff[fullname]['total'] += float(seconds)
+  stuff[fullname]['num'] += 1
+
+for i in stuff.keys():
+  stuff[i]['mean'] = stuff[i]['total']/stuff[i]['num']
+
+stuff = stuff.values()
+
+def nicify(item):
+  return '%50s     %10.4f total seconds  %10.4f mean seconds  %10d counted' % (
+    item['name'], item['total'], item['mean'], item['num']
+  )
+
+print '\n\n'
+
+print "                                                     === By total seconds ===\n"
+stuff.sort(key=lambda item: -item['total'])
+print '\n'.join(map(nicify, stuff))
+print '\n\n\n'
+
+print "                                                     === By mean seconds ===\n"
+stuff.sort(key=lambda item: -item['mean'])
+print '\n'.join(map(nicify, stuff))
+print '\n\n\n'
+
+print "                                                     === By number ===\n"
+stuff.sort(key=lambda item: -item['num'])
+print '\n'.join(map(nicify, stuff))
+print '\n\n\n'
+