plotter.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. process_data = [
  5. {'cargaTick': 3, 'primerTick': 4, 'ticksBlock': 9, 'ticksCpu': 11, 'ultimoTick': 24},
  6. {'cargaTick': 5, 'primerTick': 25, 'ticksBlock': 11, 'ticksCpu': 5, 'ultimoTick': 41},
  7. {'cargaTick': 5, 'primerTick': 42, 'ticksBlock': 12, 'ticksCpu': 5, 'ultimoTick': 59}
  8. ]
  9. fig, ax = plt.subplots(figsize=(10,5))
  10. index = list(range(len(process_data)))
  11. bar_width = 0.25
  12. opacity = 0.9
  13. error_config = {'ecolor': '0.3'}
  14. def latency(p):
  15. return p["primerTick"]-p["cargaTick"]
  16. def ready(p):
  17. return (p["ultimoTick"]-p["primerTick"])-(p["ticksBlock"]+p["ticksCpu"])+(p["primerTick"]-p["cargaTick"])
  18. def cpu(p):
  19. return p["ticksCpu"]
  20. def cpu_io(p):
  21. return p["ticksBlock"]+p["ticksCpu"]
  22. def plot_data(ind, data, color, label):
  23. plt.bar([i + bar_width*ind for i in index],
  24. data,
  25. bar_width,
  26. alpha=opacity,
  27. color=color,
  28. error_kw=error_config,
  29. label=(label))
  30. plot_data(0,[latency(p) for p in process_data], 'r', 'Latency')
  31. plot_data(1,[ready(p) for p in process_data], 'g', 'Ready')
  32. plot_data(2,[cpu(p) for p in process_data], 'b', 'CPU')
  33. plot_data(3,[cpu_io(p) for p in process_data], '#fafafa', 'CPU+IO')
  34. ax.set_ylabel('Time')
  35. ax.set_title('title')
  36. ax.set_xticks([ i + 1.5 * bar_width for i in index])
  37. ax.set_xticklabels(["Process %d" % i for i in xrange(len(process_data))])
  38. plt.legend()
  39. plt.tight_layout()
  40. plt.grid()
  41. plt.show()