perf-plot.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python3
  2. import matplotlib
  3. matplotlib.use('Agg')
  4. import matplotlib.pyplot as plt
  5. import json
  6. import sys
  7. stages_to_counters = {}
  8. stages_to_time = {}
  9. if len(sys.argv) != 2:
  10. print(f"USAGE: {sys.argv[0]} <input file>")
  11. sys.exit(1)
  12. with open(sys.argv[1]) as fh:
  13. for line in fh.readlines():
  14. if "COUNTER" in line:
  15. json_part = line[line.find("{"):]
  16. x = json.loads(json_part)
  17. counter = x['name']
  18. if not (counter in stages_to_counters):
  19. stages_to_counters[counter] = []
  20. stages_to_time[counter] = []
  21. stages_to_counters[counter].append(x['counts'])
  22. stages_to_time[counter].append(x['now'])
  23. fig, ax = plt.subplots()
  24. for stage in stages_to_counters.keys():
  25. plt.plot(stages_to_time[stage], stages_to_counters[stage], label=stage)
  26. plt.xlabel('ms')
  27. plt.ylabel('count')
  28. plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
  29. ncol=2, mode="expand", borderaxespad=0.)
  30. plt.locator_params(axis='x', nbins=10)
  31. plt.grid(True)
  32. plt.savefig("perf.pdf")