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]))