-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathshow-tps.py
77 lines (62 loc) · 2.49 KB
/
show-tps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import io
import requests
import zipfile
import re
import os
token = os.getenv("GITHUB_TOKEN")
headers = {"Authorization": f"token {token}"}
res = {}
def getTPS(url):
response = requests.get(url, headers=headers)
if response.status_code == 200:
zip_file = zipfile.ZipFile(io.BytesIO(response.content))
for file_name in zip_file.namelist():
if 'Build Chain' not in file_name: continue
with zip_file.open(file_name) as file:
content = file.read().decode('utf-8')
lastLine = content.splitlines()[-1]
print(lastLine)
pattern = r"Best TPS: (\d+) GasUsed%: ([\d.]+)"
match = re.search(pattern, lastLine)
if match:
best_tps = int(match.group(1))
gas_used = float(match.group(2))
return best_tps, gas_used
return None, None
resp = requests.get('https://api.github.com/repos/0glabs/evmchainbench/actions/workflows', headers=headers).json()
for workflow in resp['workflows']:
name = workflow['name'].split('-')
if len(name) < 2: continue
chain = name[1].strip()
category = 'Simple' if len(name) < 3 else name[2].strip()
print(chain, category)
runs = requests.get(f'{workflow['url']}/runs', headers=headers).json()
for run in runs['workflow_runs']:
if run['conclusion'] == 'success':
print(run['logs_url'])
best_tps, gas_used = getTPS(run['logs_url'])
print(best_tps, gas_used)
if chain not in res:
res[chain] = {}
res[chain][category] = (best_tps, gas_used)
break
print(res)
from prettytable import PrettyTable
table = PrettyTable()
table.field_names = ["Chain", "Simple", "ERC20", "Uniswap"]
for chain, contracts in res.items():
row = [chain]
for contract_type in ["Simple", "ERC20", "Uniswap"]:
tps, gas_used = contracts[contract_type]
if tps is None or gas_used is None:
row.append("")
else:
row.append(f"{tps:4}")
table.add_row(row)
markdown_table = "| " + " | ".join(table.field_names) + " |\n"
markdown_table += "| " + " | ".join(["---"] * len(table.field_names)) + " |\n"
for row in table.rows:
markdown_table += "| " + " | ".join(map(str, row)) + " |\n"
with open(os.getenv('GITHUB_STEP_SUMMARY'), 'a') as summary_file:
summary_file.write("### Performance Table\n")
summary_file.write(markdown_table + "\n")