From 3a3eb26acc8457add44099b0af5d2a872db8b92f Mon Sep 17 00:00:00 2001 From: Siddarth Kumar Date: Mon, 6 Jan 2025 10:30:07 +0530 Subject: [PATCH 1/2] blocks-import-script: add --markdown flag --- scripts/block-import-stats.py | 77 +++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/scripts/block-import-stats.py b/scripts/block-import-stats.py index 7e54b4c35..9819568dd 100644 --- a/scripts/block-import-stats.py +++ b/scripts/block-import-stats.py @@ -52,6 +52,39 @@ def formatBins(df: pd.DataFrame, bins: int): return df +def write_markdown_output(df_stats, df, baseline_name, contender_name): + """Write statistics in markdown table format""" + total_blocks = df.block_number.max() - df.block_number.min() + time_xt = df.time_x.sum() + time_yt = df.time_y.sum() + timet = time_yt - time_xt + + print(f"\n## {os.path.basename(baseline_name)} vs {os.path.basename(contender_name)}\n") + + print("| Block Range | BPS Baseline | BPS Contender | TPS Baseline | TPS Contender | Time Baseline | Time Contender | BPS Diff | TPS Diff | Time Diff |") + print("|------------|--------------|---------------|--------------|---------------|---------------|----------------|----------|----------|-----------|") + + for idx, row in df_stats.iterrows(): + print(f"| {str(idx)} | {row['bps_x']:.2f} | {row['bps_y']:.2f} | {row['tps_x']:.2f} | {row['tps_y']:.2f} | {prettySecs(row['time_x'])} | {prettySecs(row['time_y'])} | {row['bpsd']:.2%} | {row['tpsd']:.2%} | {row['timed']:.2%} |") + + print("\n## Summary\n") + + print("| Metric | Value |") + print("|--------|-------|") + + print(f"| Total Blocks | {total_blocks} |") + print(f"| Baseline Time | {prettySecs(time_xt)} |") + print(f"| Contender Time | {prettySecs(time_yt)} |") + print(f"| Time Difference | {prettySecs(timet)} |") + print(f"| Time Difference % | {(timet/time_xt):.2%} |") + + print("\n## Legend\n") + print("- BPS Diff: Blocks per second difference (+)") + print("- TPS Diff: Transactions per second difference") + print("- Time Diff: Time to process difference (-)") + print("\n(+) = more is better, (-) = less is better") + + def write_csv_output(df_stats, df, csv_path): """Write statistics to a CSV file""" total_blocks = df.block_number.max() - df.block_number.min() @@ -88,12 +121,32 @@ def write_csv_output(df_stats, df, csv_path): csv_writer.writerow(['Time Difference %', f"{(timet/time_xt):.2%}"]) +def write_standard_output(df_stats, df, baseline_name, contender_name): + print(f"{os.path.basename(baseline_name)} vs {os.path.basename(contender_name)}") + print(df_stats.to_string( + formatters=dict.fromkeys(["bpsd", "tpsd", "timed"], "{:,.2%}".format) + | dict.fromkeys(["bps_x", "bps_y", "tps_x", "tps_y"], "{:,.2f}".format) + | dict.fromkeys(["time_x", "time_y"], prettySecs), + )) + + total_blocks = df.block_number.max() - df.block_number.min() + time_xt = df.time_x.sum() + time_yt = df.time_y.sum() + timet = time_yt - time_xt + + print(f"\nblocks: {total_blocks}, baseline: {prettySecs(time_xt)}, contender: {prettySecs(time_yt)}") + print(f"Time (total): {prettySecs(timet)}, {(timet/time_xt):.2%}") + print("\nbpsd = blocks per sec diff (+), tpsd = txs per sec diff, timed = time to process diff (-)") + print("+ = more is better, - = less is better") + + def main(): parser = argparse.ArgumentParser() parser.add_argument("baseline") parser.add_argument("contender") parser.add_argument("--plot", action="store_true") parser.add_argument("--csv-output", type=str, help="Path to output CSV file") + parser.add_argument("--markdown", action="store_true", help="Output in markdown table format") parser.add_argument( "--bins", default=10, @@ -122,8 +175,8 @@ def main(): print(f"Contender range: {min(contender.index)} to {max(contender.index)}") exit(1) - baseline = baseline.loc[baseline.index >= start and baseline.index <= end] - contender = contender.loc[contender.index >= start and contender.index <= end] + baseline = baseline.loc[start:end] + contender = contender.loc[start:end] # Join the two frames then interpolate - this helps dealing with runs that # haven't been using the same chunking and/or max-blocks @@ -176,23 +229,11 @@ def main(): if args.csv_output: write_csv_output(stats_df, df, args.csv_output) - print(f"{os.path.basename(args.baseline)} vs {os.path.basename(args.contender)}") - print(stats_df.to_string( - formatters=dict.fromkeys(["bpsd", "tpsd", "timed"], "{:,.2%}".format) - | dict.fromkeys(["bps_x", "bps_y", "tps_x", "tps_y"], "{:,.2f}".format) - | dict.fromkeys(["time_x", "time_y"], prettySecs), - )) - - total_blocks = df.block_number.max() - df.block_number.min() - time_xt = df.time_x.sum() - time_yt = df.time_y.sum() - timet = time_yt - time_xt - - print(f"\nblocks: {total_blocks}, baseline: {prettySecs(time_xt)}, contender: {prettySecs(time_yt)}") - print(f"Time (total): {prettySecs(timet)}, {(timet/time_xt):.2%}") - print("\nbpsd = blocks per sec diff (+), tpsd = txs per sec diff, timed = time to process diff (-)") - print("+ = more is better, - = less is better") + if args.markdown: + write_markdown_output(stats_df, df, args.baseline, args.contender) + else: + write_standard_output(stats_df, df, args.baseline, args.contender) if __name__ == "__main__": main() From 6d5cf8e24168f35e6c47d19b0b905874f296f96a Mon Sep 17 00:00:00 2001 From: Siddarth Kumar Date: Tue, 7 Jan 2025 18:42:25 +0530 Subject: [PATCH 2/2] blocks-import-script: remove csv-output flag --- scripts/block-import-stats.py | 41 ----------------------------------- 1 file changed, 41 deletions(-) diff --git a/scripts/block-import-stats.py b/scripts/block-import-stats.py index 9819568dd..62d6ece03 100644 --- a/scripts/block-import-stats.py +++ b/scripts/block-import-stats.py @@ -2,7 +2,6 @@ import numpy as np import matplotlib.pyplot as plt import os -import csv import argparse plt.rcParams["figure.figsize"] = [40, 30] @@ -85,42 +84,6 @@ def write_markdown_output(df_stats, df, baseline_name, contender_name): print("\n(+) = more is better, (-) = less is better") -def write_csv_output(df_stats, df, csv_path): - """Write statistics to a CSV file""" - total_blocks = df.block_number.max() - df.block_number.min() - time_xt = df.time_x.sum() - time_yt = df.time_y.sum() - timet = time_yt - time_xt - - with open(csv_path, 'w', newline='') as csvfile: - csv_writer = csv.writer(csvfile) - - csv_writer.writerow(['block_range', 'bps_x', 'bps_y', 'tps_x', 'tps_y', - 'time_x', 'time_y', 'bpsd', 'tpsd', 'timed']) - - for idx, row in df_stats.iterrows(): - csv_writer.writerow([ - str(idx), # block range - f"{row['bps_x']:.2f}", - f"{row['bps_y']:.2f}", - f"{row['tps_x']:.2f}", - f"{row['tps_y']:.2f}", - prettySecs(row['time_x']), - prettySecs(row['time_y']), - f"{row['bpsd']:.2%}", - f"{row['tpsd']:.2%}", - f"{row['timed']:.2%}" - ]) - - csv_writer.writerow([]) - - csv_writer.writerow(['Total Blocks', total_blocks]) - csv_writer.writerow(['Baseline Time', prettySecs(time_xt)]) - csv_writer.writerow(['Contender Time', prettySecs(time_yt)]) - csv_writer.writerow(['Time Difference', prettySecs(timet)]) - csv_writer.writerow(['Time Difference %', f"{(timet/time_xt):.2%}"]) - - def write_standard_output(df_stats, df, baseline_name, contender_name): print(f"{os.path.basename(baseline_name)} vs {os.path.basename(contender_name)}") print(df_stats.to_string( @@ -145,7 +108,6 @@ def main(): parser.add_argument("baseline") parser.add_argument("contender") parser.add_argument("--plot", action="store_true") - parser.add_argument("--csv-output", type=str, help="Path to output CSV file") parser.add_argument("--markdown", action="store_true", help="Output in markdown table format") parser.add_argument( "--bins", @@ -226,9 +188,6 @@ def main(): | dict.fromkeys(["bpsd", "tpsd", "timed"], "mean") ) - if args.csv_output: - write_csv_output(stats_df, df, args.csv_output) - if args.markdown: write_markdown_output(stats_df, df, args.baseline, args.contender)