Commit 75e4b4ca authored by Joanne Hugé's avatar Joanne Hugé

Add histogram graph generation

parent 3b6cad1a
...@@ -7,9 +7,14 @@ import argparse ...@@ -7,9 +7,14 @@ import argparse
import os import os
import parse import parse
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
class MeasureSetHandler: class MeasureSetHandler:
measures_dir = "measures" measures_dir = "measures"
graphs_dir = "{}/graphs".format(measures_dir)
measure_sets_file_name = "measure_sets.json" measure_sets_file_name = "measure_sets.json"
measure_sets_path = measures_dir + "/" + measure_sets_file_name measure_sets_path = measures_dir + "/" + measure_sets_file_name
...@@ -70,6 +75,14 @@ class MeasureSetHandler: ...@@ -70,6 +75,14 @@ class MeasureSetHandler:
self.remove_measure_set(mtype, mid) self.remove_measure_set(mtype, mid)
print("Removed all measures".format(mtype, mid)) print("Removed all measures".format(mtype, mid))
def generate_graphs(self):
for mtype in self.measure_sets:
for mid in self.measure_sets[mtype]['ids']:
measure = self.get_measure_set("{}{}".format(mtype, mid))
graph_name = "{}{}".format(mtype, mid)
measure.generate_graph(graph_name, "{}/{}".format(MeasureSetHandler.graphs_dir, graph_name))
def generate_tables(self): def generate_tables(self):
with open(self.measures_dir + "/" + "measure_tables.md", 'w+') as measure_table: with open(self.measures_dir + "/" + "measure_tables.md", 'w+') as measure_table:
...@@ -202,7 +215,7 @@ class MeasureSet: ...@@ -202,7 +215,7 @@ class MeasureSet:
def histogram_to_chronological(histogram): def histogram_to_chronological(histogram):
chrono = list(map(lambda x: [x[1]]*x[0], list(enumerate(histogram)))) chrono = list(map(lambda x: [x[0]]*x[1], list(enumerate(histogram))))
chrono = [x for l in chrono for x in l] chrono = [x for l in chrono for x in l]
return chrono return chrono
...@@ -292,8 +305,29 @@ class MeasureSet: ...@@ -292,8 +305,29 @@ class MeasureSet:
self.add_chronological(props_names, props) self.add_chronological(props_names, props)
def generate_graph(self, path): def generate_graph(self, name, path):
pass
if self.props_type == 'histogram':
for i in range(len(self.props)):
histogram = MeasureSet.histogram_to_chronological(self.props[i])
n, bins, patches = plt.hist(histogram, len(self.props[i]), facecolor='red', alpha=0.5)
max_height = max([patch.get_height() for patch in patches])
min_height = max_height / 100.0
for j, patch in enumerate(patches):
height = patch.get_height()
if self.props[i][j] > 0 and height < min_height:
patch.set_height(min_height)
fig, ax = plt.gcf(), plt.gca()
ax.set_xlabel('Latency (us)')
ax.set_ylabel('Number of latency samples')
ax.set_title('{}, {} histogram'.format(name, self.props_names[i]))
fig.set_size_inches(11.0, 5.5)
plt.savefig("{}{}.png".format(path, i))
def generate_table(self, headers=True, values=True, metadata_mask=[], props_lens=[]): def generate_table(self, headers=True, values=True, metadata_mask=[], props_lens=[]):
...@@ -348,6 +382,7 @@ def parse_args(): ...@@ -348,6 +382,7 @@ def parse_args():
parser.add_argument('--remove-all', action='store_true', help='remove all measure sets') parser.add_argument('--remove-all', action='store_true', help='remove all measure sets')
parser.add_argument('-t', nargs='?', const='input_file', required=False, help='generate table') parser.add_argument('-t', nargs='?', const='input_file', required=False, help='generate table')
parser.add_argument('-T', action='store_true', required=False, help='generate all tables') parser.add_argument('-T', action='store_true', required=False, help='generate all tables')
parser.add_argument('-G', action='store_true', required=False, help='generate all graphs')
parser.add_argument('-s', action='store_true', help='show measures') parser.add_argument('-s', action='store_true', help='show measures')
args = parser.parse_args() args = parser.parse_args()
...@@ -374,6 +409,9 @@ def parse_args(): ...@@ -374,6 +409,9 @@ def parse_args():
if args.T: if args.T:
ms_handler.generate_tables() ms_handler.generate_tables()
if args.G:
ms_handler.generate_graphs()
if args.remove_all: if args.remove_all:
confirm = input("Are you sure all measure sets should be removed ? [Yes] / [No]: ") confirm = input("Are you sure all measure sets should be removed ? [Yes] / [No]: ")
if confirm == "Yes": if confirm == "Yes":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment