From 301922d472c1b0f5454aa5ae54358dfcd8a9e596 Mon Sep 17 00:00:00 2001 From: Justin Bassett Date: Fri, 16 Jul 2021 17:34:18 -0700 Subject: [PATCH] Add tool to combine sharded csv metrics --- util/misc/merge-csv.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 util/misc/merge-csv.py diff --git a/util/misc/merge-csv.py b/util/misc/merge-csv.py new file mode 100644 index 000000000..7adabd721 --- /dev/null +++ b/util/misc/merge-csv.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +import argparse +import csv +import sys + + +def main(infile, outfile): + metrics = {} + metric_names = [] + + for metric, total, bench in csv.reader(infile): + assert total == bench + if metric not in metrics: + metric_names.append(metric) + + metrics.setdefault(metric, []).append(bench) + + writer = csv.writer(outfile) + for metric in metric_names: + try: + writer.writerow([metric, sum(metrics[metric]), *metrics[metric]]) + except TypeError: + writer.writerow([metric, 'Total', *metrics[metric]]) + + +if __name__ == '__main__': + main(sys.stdin, sys.stdout)