From 5e32cce2d92e3bd802dec58eaa7f032154824343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arpad=20M=C3=BCller?= Date: Sat, 22 Jun 2024 18:14:05 +0200 Subject: [PATCH] Add script for plots --- scripts/plot-compression-report.py | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 scripts/plot-compression-report.py diff --git a/scripts/plot-compression-report.py b/scripts/plot-compression-report.py new file mode 100755 index 000000000000..ab625c649ea7 --- /dev/null +++ b/scripts/plot-compression-report.py @@ -0,0 +1,63 @@ +#!/usr/bin/env -S python3 -u + +import argparse +import json +import os +from pprint import pprint + +import matplotlib.pyplot as plt + +parser = argparse.ArgumentParser(prog="compression-report") +parser.add_argument("dir") +args = parser.parse_args() + +files = [] +for file_name in os.listdir(args.dir): + if not file_name.endswith(".json"): + continue + file_path = os.path.join(args.dir, file_name) + with open(file_path) as json_str: + json_data = json.load(json_str) + files.append((file_name, json_data)) +#pprint(files) + +extra_zstd_lines = True +dc = 2 # data column to use (1 for sizes, 2 for time) +sort_by = "ZstdHigh" +files.sort(key=lambda file_data: [x for x in file_data[1] if x[0] == sort_by][0][dc]) + + +x_axis = [] +data_baseline = [] +data_lz4 = [] +data_zstd = [] +data_zstd_low = [] +data_zstd_high = [] + +for idx, f in enumerate(files): + file_data = f[1] + #pprint(file_data) + + x_axis.append(idx) + data_baseline.append([x for x in file_data if x[0] is None][0][dc]) + data_lz4.append([x for x in file_data if x[0] == "LZ4"][0][dc]) + data_zstd.append([x for x in file_data if x[0] == "Zstd"][0][dc]) + if extra_zstd_lines: + data_zstd_low.append([x for x in file_data if x[0] == "ZstdLow"][0][dc]) + data_zstd_high.append([x for x in file_data if x[0] == "ZstdHigh"][0][dc]) + +plt.plot(x_axis, data_baseline, "x", markeredgewidth=2, label="baseline") +plt.plot(x_axis, data_lz4, "x", markeredgewidth=2, label="lz4") +plt.plot(x_axis, data_zstd, "x", markeredgewidth=2, label="Zstd") +if extra_zstd_lines: + plt.plot(x_axis, data_zstd_low, "x", markeredgewidth=2, label="ZstdLow") + plt.plot(x_axis, data_zstd_high, "x", markeredgewidth=2, label="ZstdHigh") + +# plt.style.use('_mpl-gallery') +plt.ylim(bottom=0) +plt.legend(loc="upper left") + +figure_path = os.path.join(args.dir, "figure.png") +print(f"saving figure to {figure_path}") +plt.savefig(figure_path) +plt.show()