Browse Source

Add script to analyse profiling results

Yentl Van Tendeloo 3 years ago
parent
commit
cb9beb4604
1 changed files with 34 additions and 0 deletions
  1. 34 0
      scripts/analyse_profiler.py

+ 34 - 0
scripts/analyse_profiler.py

@@ -0,0 +1,34 @@
+import json
+
+tottime = {}
+cumtime = {}
+
+with open("profiling_results", "r") as f:
+    for l in f:
+        stack = json.loads(l)
+        t = stack.pop()
+
+        if stack:
+            prev = None
+            for func in set(stack):
+                cumtime[func] = cumtime.get(func, 0.0) + t
+            tottime[stack[-1]] = tottime.get(stack[-1], 0.0) + t
+
+max_tot = sorted(tottime.keys(), key=lambda i: -tottime[i])
+max_cum = sorted(cumtime.keys(), key=lambda i: -cumtime[i])
+
+print("TOTTIME")
+for f in max_tot:
+    print("%s -- %s -- %s" % (f, tottime[f], cumtime[f]))
+
+print("")
+print("")
+print("CUMTIME")
+for f in max_cum:
+    print("%s -- %s -- %s" % (f, tottime[f], cumtime[f]))
+
+print("")
+print("")
+print("NAME")
+for f in sorted(tottime.keys()):
+    print("%s -- %s -- %s" % (f, tottime[f], cumtime[f]))