[why]
friendly show compare template result in command line.
[how]
rehandle the json format result of "compare -t <compare_template.yaml>"
with third-party module in python3.
[usage]
compare_template <compare_template.yaml>
[example]
compare_template compare_template.yaml
in z9
[input]
a compare_template.yaml like below:
compare_metrics:
- fio.write_iops
- fio.read_iops
filter:
suite:
- fio-basic
os_arch:
- aarch64
- x86
compare_dimensions:
- os: debian
os_version: sid
- os: openeuler
os_version: 20.03
x_params:
- bs
- test_size
title: Hackbench Performance Testing
unit: KB/s
[output]
Hackbench Performance Testing
+------------------------------------+-----------+----------+----------+----------+----------+---------+---------+---------+----------+
| fio.read_iops | 4k|1G | 4k|80G | 16k|1G | 32k|1G | 64k|1G | 128k|1G | 256k|1G | 512k|1G | 1024k|1G |
+------------------------------------+-----------+----------+----------+----------+----------+---------+---------+---------+----------+
| openeuler 20.03 average | 144076.29 | 11601.10 | 37865.30 | 21145.10 | 14010.34 | 6701.24 | 3205.08 | 1367.48 | 673.33 |
| openeuler 20.03 standard_deviation | 195.00 | 0.00 | 214.00 | 205.00 | 188.00 | 183.00 | 180.00 | 191.00 | 191.00 |
+------------------------------------+-----------+----------+----------+----------+----------+---------+---------+---------+----------+
Hackbench Performance Testing
+------------------------------------+-----------+----------+----------+----------+---------+---------+---------+----------+
| fio.write_iops | 4k|1G | 16k|1G | 32k|1G | 64k|1G | 128k|1G | 256k|1G | 512k|1G | 1024k|1G |
+------------------------------------+-----------+----------+----------+----------+---------+---------+---------+----------+
| openeuler 20.03 average | 122003.54 | 33528.53 | 31469.06 | 13870.14 | 8249.71 | 4329.45 | 1976.54 | 1141.00 |
| openeuler 20.03 standard_deviation | 174.00 | 188.00 | 171.00 | 197.00 | 181.00 | 175.00 | 170.00 | 176.00 |
+------------------------------------+-----------+----------+----------+----------+---------+---------+---------+----------+
Signed-off-by: Lu Kaiyi <2392863668(a)qq.com>
---
sbin/compare_template | 53 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
create mode 100755 sbin/compare_template
diff --git a/sbin/compare_template b/sbin/compare_template
new file mode 100755
index 0000000..6b702c0
--- /dev/null
+++ b/sbin/compare_template
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: MulanPSL-2.0+
+# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+
+import os
+import sys
+import json
+import prettytable as pt
+
+# receive compare_template.yaml and auto pretty show compare results
+class TableShow:
+ def __init__(self, result_dict):
+ self.title = result_dict['title']
+ self.tables = result_dict['tables']
+ self.tb = None
+
+ def show_table(self):
+ for (table_title, table) in self.tables.items():
+ self.tb = pt.PrettyTable()
+ self.set_field_names(table, table_title)
+ self.set_align(table_title)
+ self.add_row(table)
+ self.print_table()
+
+ def set_field_names(self, table, table_title):
+ field_names = [table_title]
+ field_names.extend(table['average']['source'][0])
+ self.tb.field_names = field_names
+
+ def set_align(self, table_title):
+ for field_name in self.tb.field_names:
+ self.tb.align[field_name] = 'r'
+ self.tb.align[table_title] = 'l'
+
+ def add_row(self, table):
+ row_names = ['average', 'standard_deviation']
+ for row_name in row_names:
+ row = table[row_name]['source'][1]
+ row_title = ' '.join([row[0], row_name])
+ format_data_row = ["%.2f" % data for data in row[1:]]
+ self.tb.add_row([row_title, *format_data_row])
+
+ def print_table(self):
+ print(self.title)
+ print(self.tb)
+ print()
+
+
+if __name__ == '__main__':
+ template_yaml = sys.argv[1]
+ result_dict = json.loads(os.popen(f"compare -t {template_yaml}").read())
+ table_show = TableShow(result_dict)
+ table_show.show_table()
--
2.23.0