plotter.py 1.5 KB

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