Commit 6a1b2c3f authored by Joanne Hugé's avatar Joanne Hugé

Add full report generation

parent 75e4b4ca
......@@ -77,28 +77,54 @@ class MeasureSetHandler:
def generate_graphs(self):
colors = ['red', 'blue', 'green']
for mtype in self.measure_sets:
measures = []
for mid in self.measure_sets[mtype]['ids']:
measures.append(self.get_measure_set("{}{}".format(mtype, mid)))
if len(measures) == 0:
continue
nb_props = len(measures[0].props)
for i in range(nb_props):
for j, mid in enumerate(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):
measure.generate_histogram(i, colors[j])
with open(self.measures_dir + "/" + "measure_tables.md", 'w+') as measure_table:
fig, ax = plt.gcf(), plt.gca()
ax.set_xlabel('Latency (us)')
ax.set_ylabel('Number of latency samples')
ax.set_title('{}, {} histogram'.format(mtype, measures[0].props_names[i]))
fig.set_size_inches(11.0, 5.5)
measure_table.write("## Measurements tables\n\n")
plt.savefig("{}/{}{}.png".format(MeasureSetHandler.graphs_dir, mtype, measures[0].props_names[i]))
measure_table.write("### Abbreviations used\n\n")
def generate_report(self, include_graphs=True):
if include_graphs:
self.generate_graphs()
with open(self.measures_dir + "/" + "measure-report.md", 'w+') as report:
report.write("## Measurements\n\n")
report.write("### Abbreviations used\n\n")
for abbr_name in MeasureSet.abbreviations:
measure_table.write("* {}: {}\n".format(abbr_name, MeasureSet.abbreviations[abbr_name]))
measure_table.write("\n")
report.write("* {}: {}\n".format(abbr_name, MeasureSet.abbreviations[abbr_name]))
report.write("\n")
for mtype in self.measure_sets:
need_header = True
props_lens = []
measure_table.write("### {} tables\n\n".format(mtype))
report.write("### {} tables\n\n".format(mtype))
# Generate the metadata mask, by grouping the identical metadatas
metadata_mask = []
......@@ -120,12 +146,12 @@ class MeasureSetHandler:
# Write the identical metadatas before the table
measure_table.write("**Common metadatas:** ")
report.write("**Common metadatas:** ")
common_metadatas = []
for metadata_name in first_metadata:
if metadata_name not in metadata_mask:
common_metadatas.append("{}: {}".format(MeasureSet.abbreviations[metadata_name], first_metadata[metadata_name]))
measure_table.write(", ".join(common_metadatas) + "\n\n")
report.write(", ".join(common_metadatas) + "\n\n")
for mid in self.measure_sets[mtype]['ids']:
......@@ -134,14 +160,22 @@ class MeasureSetHandler:
if need_header:
table_str, props_lens = measure.generate_table(headers=True, metadata_mask=metadata_mask)
measure_table.write(table_str)
report.write(table_str)
need_header = False
else:
measure_table.write(measure.generate_table(headers=False, props_lens=props_lens, metadata_mask=metadata_mask)[0])
report.write(measure.generate_table(headers=False, props_lens=props_lens, metadata_mask=metadata_mask)[0])
measure_table.write("\n")
measure_table.write("\n")
measure_table.write("\n")
report.write("\n")
# Include the graphs
if include_graphs:
for i in range(len(measures[0].props)):
report.write('\n![alt text](graphs/{}{}.png "{} Graph")\n'.format(mtype,
measures[0].props_names[i],
mtype,
measures[0].props_names[i]))
report.write("\n")
report.write("\n")
class MeasureSet:
......@@ -170,7 +204,7 @@ class MeasureSet:
def __str__(self):
return "Cols: " + str(self.props) + "\nInterval: " + str(self.interval)
return "Cols: " + str(self.props) + "\n"
def input_metadata(self):
......@@ -305,12 +339,9 @@ class MeasureSet:
self.add_chronological(props_names, props)
def generate_graph(self, name, path):
if self.props_type == 'histogram':
for i in range(len(self.props)):
def generate_histogram(self, i, color):
histogram = MeasureSet.histogram_to_chronological(self.props[i])
n, bins, patches = plt.hist(histogram, len(self.props[i]), facecolor='red', alpha=0.5)
n, bins, patches = plt.hist(histogram, len(self.props[i]), facecolor=color, alpha=0.5)
max_height = max([patch.get_height() for patch in patches])
min_height = max_height / 100.0
......@@ -320,15 +351,6 @@ class MeasureSet:
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=[]):
if headers == False and values == False:
......@@ -381,7 +403,7 @@ def parse_args():
parser.add_argument('-c', action='store_true', required=False, help='parse cyclictest histogram')
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', action='store_true', required=False, help='generate all tables')
parser.add_argument('-R', action='store_true', required=False, help='generate full measure report')
parser.add_argument('-G', action='store_true', required=False, help='generate all graphs')
parser.add_argument('-s', action='store_true', help='show measures')
......@@ -406,8 +428,8 @@ def parse_args():
measure_set = ms_handler.get_measure_set(args.t)
print(measure_set.generate_table(True, True, {'board', 'linux_version', 'boot_params'})[0])
if args.T:
ms_handler.generate_tables()
if args.R:
ms_handler.generate_report()
if args.G:
ms_handler.generate_graphs()
......
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