plotter.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python3
  2. import json
  3. import matplotlib.pyplot as plt
  4. import sys
  5. bar_width = 0.25
  6. index = []
  7. def plot(process_data):
  8. fig, ax = plt.subplots(figsize=(10,5))
  9. plot_data(0,[latency(p) for p in process_data], 'r', 'Latency')
  10. plot_data(1,[ready(p) for p in process_data], 'g', 'Ready')
  11. plot_data(2,[cpu(p) for p in process_data], 'b', 'CPU')
  12. plot_data(3,[cpu_io(p) for p in process_data], '#deadbe', 'CPU+IO')
  13. ax.set_ylabel('Time')
  14. ax.set_title('title')
  15. ax.set_xticks([ i + 1.5 * bar_width for i in index])
  16. ax.set_xticklabels(["Process %d" % i for i in range(len(process_data))])
  17. plt.legend()
  18. plt.tight_layout()
  19. plt.grid()
  20. plt.savefig('out.png')
  21. plt.show()
  22. def latency(p):
  23. return p["primerTick"]-p["cargaTick"]
  24. def ready(p):
  25. return (p["ultimoTick"]-p["primerTick"])-(p["ticksBlock"]+p["ticksCpu"])+(p["primerTick"]-p["cargaTick"])
  26. def cpu(p):
  27. return p["ticksCpu"]
  28. def cpu_io(p):
  29. return p["ticksBlock"]+p["ticksCpu"]
  30. def plot_data(ind, data, color, label):
  31. opacity = 1
  32. plt.bar([i + bar_width*ind for i in index],
  33. data,
  34. bar_width,
  35. alpha=opacity,
  36. color=color,
  37. label=(label))
  38. if sys.stdin.isatty():
  39. print("lol")
  40. sys.exit(1)
  41. try:
  42. data = sys.stdin.read()
  43. data = json.loads(data)
  44. index = [ 1.2*i for i in list(range(len(data))) ]
  45. plot(data)
  46. except Exception as e:
  47. print(data)
  48. print(e)