Skip to content

Commit

Permalink
blocks-import-script: add --markdown flag
Browse files Browse the repository at this point in the history
  • Loading branch information
siddarthkay committed Jan 6, 2025
1 parent 0ffc17d commit bb00e61
Showing 1 changed file with 55 additions and 18 deletions.
73 changes: 55 additions & 18 deletions scripts/block-import-stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -94,6 +127,7 @@ def main():
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,
Expand Down Expand Up @@ -122,8 +156,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
Expand Down Expand Up @@ -176,22 +210,25 @@ 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:
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 __name__ == "__main__":
Expand Down

0 comments on commit bb00e61

Please sign in to comment.