sum_times.py 713 B

12345678910111213141516171819202122232425
  1. import sys
  2. tottimes = {}
  3. cumtimes = {}
  4. for l in open(sys.argv[1], "r"):
  5. r = l.rsplit(" : ", 2)
  6. if len(r) == 3:
  7. func, cumtime, tottime = r
  8. cumtime = float(cumtime)
  9. tottime = float(tottime)
  10. tottimes[func] = tottimes.get(func, 0.0) + tottime
  11. cumtimes[func] = cumtimes.get(func, 0.0) + cumtime
  12. lists = [(funcname, tottimes[funcname], cumtimes[funcname]) for funcname in tottimes]
  13. c = 0
  14. lists.sort(key=lambda i: i[int(sys.argv[2])])
  15. for func, tottime, cumtime in reversed(lists):
  16. if not func.startswith("jit"):
  17. print("%s = %s (%s)" % (func, tottime, cumtime))
  18. c += 1
  19. if c > int(sys.argv[3]):
  20. break