analyse_profiler.py 810 B

1234567891011121314151617181920212223242526272829303132333435
  1. import json
  2. tottime = {}
  3. cumtime = {}
  4. with open("profiling_results", "r") as f:
  5. for l in f:
  6. stack = json.loads(l)
  7. t = stack.pop()
  8. if stack:
  9. prev = None
  10. for func in set(stack):
  11. cumtime[func] = cumtime.get(func, 0.0) + t
  12. tottime[stack[-1]] = tottime.get(stack[-1], 0.0) + t
  13. max_tot = sorted(tottime.keys(), key=lambda i: -tottime[i])
  14. max_cum = sorted(cumtime.keys(), key=lambda i: -cumtime[i])
  15. print("TOTTIME")
  16. for f in max_tot:
  17. print("%s -- %s -- %s" % (f, tottime[f], cumtime[f]))
  18. print("")
  19. print("")
  20. print("CUMTIME")
  21. for f in max_cum:
  22. print("%s -- %s -- %s" % (f, tottime[f], cumtime[f]))
  23. print("")
  24. print("")
  25. print("NAME")
  26. for f in sorted(tottime.keys()):
  27. print("%s -- %s -- %s" % (f, tottime[f], cumtime[f]))