| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #!/usr/bin/env python3
- import json
- import matplotlib.pyplot as plt
- import sys
- bar_width = 0.25
- index = []
- def plot(process_data):
- fig, ax = plt.subplots(figsize=(10,5))
-
- plot_data(0,[latency(p) for p in process_data], 'r', 'Latency')
- plot_data(1,[ready(p) for p in process_data], 'g', 'Ready')
- plot_data(2,[cpu(p) for p in process_data], 'b', 'CPU')
- plot_data(3,[cpu_io(p) for p in process_data], '#deadbe', 'CPU+IO')
-
- ax.set_ylabel('Time')
- ax.set_title('title')
- ax.set_xticks([ i + 1.5 * bar_width for i in index])
- ax.set_xticklabels(["Process %d" % i for i in range(len(process_data))])
-
- plt.legend()
-
- plt.tight_layout()
- plt.grid()
- plt.savefig('out.png')
- plt.show()
- def latency(p):
- return p["primerTick"]-p["cargaTick"]
- def ready(p):
- return (p["ultimoTick"]-p["primerTick"])-(p["ticksBlock"]+p["ticksCpu"])+(p["primerTick"]-p["cargaTick"])
- def cpu(p):
- return p["ticksCpu"]
- def cpu_io(p):
- return p["ticksBlock"]+p["ticksCpu"]
- def plot_data(ind, data, color, label):
- opacity = 1
- plt.bar([i + bar_width*ind for i in index],
- data,
- bar_width,
- alpha=opacity,
- color=color,
- label=(label))
- if sys.stdin.isatty():
- print("lol")
- sys.exit(1)
- try:
- data = sys.stdin.read()
- data = json.loads(data)
- index = [ 1.2*i for i in list(range(len(data))) ]
- plot(data)
- except Exception as e:
- print(data)
- print(e)
|