[why]
if too much columns in a row, it's ugly in command line display.
[how]
add row_size limit to split the table columns to multi-table.
[example]
compare_template compare_template.yaml
[output]
Hackbench Performance Testing
+------------------------------------+------------+-----------+-----------+-----------+------------+-----------+-----------+------------+
| meminfo.Active | 4k|1G | 4k|10G | 4k|80G | 4k|100G | 16k|1G | 16k|10G | 16k|100G | 32k|1G |
+------------------------------------+------------+-----------+-----------+-----------+------------+-----------+-----------+------------+
| openeuler 20.03 average | 1051645.34 | 704958.00 | 706798.00 | 657669.27 | 1030484.85 | 979289.00 | 948576.00 | 1262591.17 |
| openeuler 20.03 standard_deviation | 74.00 | 0.00 | 0.00 | 8.00 | 46.00 | 0.00 | 2.00 | 42.00 |
+------------------------------------+------------+-----------+-----------+-----------+------------+-----------+-----------+------------+
+------------------------------------+------------+------------+------------+------------+------------+------------+------------+------------+
| meminfo.Active | 64k|1G | 64k|100G | 128k|1G | 128k|100G | 256k|1G | 256k|100G | 512k|1G | 512k|100G |
+------------------------------------+------------+------------+------------+------------+------------+------------+------------+------------+
| openeuler 20.03 average | 1418731.53 | 1854231.33 | 2004321.76 | 2960171.75 | 2979326.50 | 4775340.00 | 5003555.53 | 5630845.75 |
| openeuler 20.03 standard_deviation | 47.00 | 10.00 | 65.00 | 18.00 | 88.00 | 8.00 | 108.00 | 15.00 |
+------------------------------------+------------+------------+------------+------------+------------+------------+------------+------------+
+------------------------------------+------------+------------+------------+
| meminfo.Active | 1024k|1G | 1024k|100G | 2048k|100G |
+------------------------------------+------------+------------+------------+
| openeuler 20.03 average | 8974190.91 | 9641039.00 | 5480763.67 |
| openeuler 20.03 standard_deviation | 118.00 | 36.00 | 86.00 |
+------------------------------------+------------+------------+------------+
Hackbench Performance Testing
+------------------------------------+------------+-------------+-------------+-------------+------------+-------------+-------------+------------+
| meminfo.Memused | 4k|1G | 4k|10G | 4k|80G | 4k|100G | 16k|1G | 16k|10G | 16k|100G | 32k|1G |
+------------------------------------+------------+-------------+-------------+-------------+------------+-------------+-------------+------------+
| openeuler 20.03 average | 9696255.67 | 17831902.00 | 17846148.00 | 17638278.33 | 9618919.65 | 18067696.00 | 18059618.20 | 6274953.67 |
| openeuler 20.03 standard_deviation | 73.00 | 0.00 | 0.00 | 3.00 | 74.00 | 0.00 | 0.00 | 89.00 |
+------------------------------------+------------+-------------+-------------+-------------+------------+-------------+-------------+------------+
...
Signed-off-by: Lu Kaiyi <2392863668(a)qq.com>
---
sbin/compare_template | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/sbin/compare_template b/sbin/compare_template
index 6b702c0..22d54e9 100755
--- a/sbin/compare_template
+++ b/sbin/compare_template
@@ -9,14 +9,16 @@ import prettytable as pt
# receive compare_template.yaml and auto pretty show compare results
class TableShow:
- def __init__(self, result_dict):
+ def __init__(self, result_dict, row_size=8):
self.title = result_dict['title']
self.tables = result_dict['tables']
+ self.row_size = row_size
self.tb = None
def show_table(self):
for (table_title, table) in self.tables.items():
self.tb = pt.PrettyTable()
+ self.tb.header = True
self.set_field_names(table, table_title)
self.set_align(table_title)
self.add_row(table)
@@ -40,9 +42,23 @@ class TableShow:
format_data_row = ["%.2f" % data for data in row[1:]]
self.tb.add_row([row_title, *format_data_row])
+ def get_row_num(self):
+ row_num, rem = divmod(len(self.tb.field_names[1:]), self.row_size)
+ if rem > 0:
+ row_num += 1
+ self.tb.row_num = row_num
+
def print_table(self):
print(self.title)
- print(self.tb)
+ self.get_row_num()
+ for row in range(self.tb.row_num):
+ start = 1 + row * self.row_size
+ end = start + self.row_size
+ if end > len(self.tb.field_names):
+ end = -1
+ # set the field names to include in displays
+ self.tb.fields = [self.tb.field_names[0], *self.tb.field_names[start:end]]
+ print(self.tb)
print()
--
2.23.0