tracy_summary.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python3
  2. """Prints the busiest zones of a Tracy capture (tracy-csvexport), and the GPU time of the zones that have it.
  3. tools/tracy_summary.py <capture.tracy> [rows]
  4. """
  5. import csv
  6. import io
  7. import statistics
  8. import subprocess
  9. import sys
  10. def export(args):
  11. result = subprocess.run(["tracy-csvexport", *args], capture_output=True, text=True, check=True)
  12. return list(csv.DictReader(io.StringIO(result.stdout)))
  13. def main():
  14. if len(sys.argv) < 2:
  15. sys.exit(__doc__)
  16. capture = sys.argv[1]
  17. rows = int(sys.argv[2]) if len(sys.argv) > 2 else 25
  18. # the aggregated export groups by source location, so zones named at run time all end up as one; each event
  19. # carries its own name
  20. times = {}
  21. for event in export(["-u", capture]):
  22. times.setdefault(event["name"], []).append(float(event["exec_time_ns"]) / 1e6)
  23. print(f"{'zone':44} {'count':>8} {'mean ms':>9} {'max ms':>9} {'total ms':>10}")
  24. for name, values in sorted(times.items(), key=lambda item: -sum(item[1]))[:rows]:
  25. print(f"{name[:44]:44} {len(values):>8} {statistics.fmean(values):>9.3f} {max(values):>9.3f} {sum(values):>10.1f}")
  26. gpu = {}
  27. for zone in export(["-g", capture]):
  28. gpu.setdefault(zone["name"], []).append(float(zone["GPU execution time"]) / 1e6)
  29. if gpu:
  30. print(f"\n{'gpu zone':44} {'count':>8} {'mean ms':>9} {'p99 ms':>9} {'max ms':>9}")
  31. for name, times in gpu.items():
  32. times.sort()
  33. print(
  34. f"{name[:44]:44} {len(times):>8} {statistics.fmean(times):>9.3f} "
  35. f"{times[int(len(times) * 0.99)]:>9.3f} {times[-1]:>9.3f}"
  36. )
  37. main()