Skip to content

Commit

Permalink
log tps
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Sep 17, 2024
1 parent 485799a commit a699f19
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion testground/benchmark/benchmark/stateless.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tarfile
import tempfile
import time
from datetime import datetime
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -410,15 +411,52 @@ def wait_for_peers(home: Path):
wait_for_port(ECHO_SERVER_PORT, host=host, timeout=2400)


def truncate_fractional_seconds(timestamp):
(
date_time_part,
_,
_,
) = timestamp.partition("Z")
if "." in date_time_part:
date_time_part, fractional_part = date_time_part.split(".")
fractional_part = fractional_part[:6]
return f"{date_time_part}.{fractional_part}Z"
return timestamp


def calculate_tps(height, num_txs, timestamp):
if height > 1:
prev_block = block(height - 1)
prev_timestamp = prev_block["result"]["block"]["header"]["time"]
time_format = "%Y-%m-%dT%H:%M:%S.%fZ"
current_time, previous_time = (
datetime.strptime(truncate_fractional_seconds(ts), time_format)
for ts in (timestamp, prev_timestamp)
)
diff = (current_time - previous_time).total_seconds()
if diff > 0:
tps = num_txs / diff
return tps
else:
return 0
else:
return 0


def dump_block_stats(fp):
"""
dump simple statistics for blocks for analysis
"""
tps_list = []
for i in range(1, block_height() + 1):
blk = block(i)
timestamp = blk["result"]["block"]["header"]["time"]
txs = len(blk["result"]["block"]["data"]["txs"])
print("block", i, txs, timestamp, file=fp)
tps = calculate_tps(i, txs, timestamp)
print("block", i, txs, timestamp, tps, file=fp)
tps_list.append(tps)
top_tps = sorted(tps_list, reverse=True)[:3]
print("top_tps", top_tps)


if __name__ == "__main__":
Expand Down

0 comments on commit a699f19

Please sign in to comment.