-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreport_speed.py
193 lines (170 loc) · 7.83 KB
/
report_speed.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import argparse
import json
import os
import numpy as np
import yaml
from bs4 import BeautifulSoup
def calculate_metrics(values):
if not values:
return {
'max': None,
'p50': None,
'p95': None,
'p99': None,
'min': None,
'count': 0
}
values = np.array(values, dtype=int)
return {
'max': int(np.max(values)),
'p50': int(np.percentile(values, 50)),
'p95': int(np.percentile(values, 95)),
'p99': int(np.percentile(values, 99)),
'min': int(np.min(values)),
'count': len(values)
}
def get_client_results(results_path):
client_results = {}
for filename in os.listdir(results_path):
if filename.endswith('.txt') and filename != "computer_specs.txt":
parts = filename.rsplit('_', 3)
if len(parts) == 4:
client, run, part, size = parts
size = size.replace('.txt', '')
try:
run = int(run)
with open(os.path.join(results_path, filename), 'r') as file:
value = int(file.read().strip())
except ValueError:
print(f"Skipping file {filename} due to invalid content")
continue
except Exception as e:
print(f"Error reading file {filename}: {e}")
continue
client = client # Keep only the client name, ignore run
if client not in client_results:
client_results[client] = {}
if size not in client_results[client]:
client_results[client][size] = {}
if part not in client_results[client][size]:
client_results[client][size][part] = []
client_results[client][size][part].append(value)
print(f"Added value for size {size}, client {client}, part {part}: {value}")
else:
print(f"Filename {filename} does not match expected pattern")
return client_results
def process_client_results(client_results):
processed_results = {}
for client, sizes in client_results.items():
processed_results[client] = {}
for size, parts in sizes.items():
processed_results[client][size] = {}
for part, values in parts.items():
processed_results[client][size][part] = calculate_metrics(values)
return processed_results
def generate_json_report(processed_results, results_path):
report_path = os.path.join(results_path, 'reports')
os.makedirs(report_path, exist_ok=True)
with open(os.path.join(report_path, 'speed.json'), 'w') as json_file:
json.dump(processed_results, json_file, indent=4)
def ms_to_readable_time(ms):
if ms is None:
return "N/A"
if ms == -1:
return "∞"
seconds = ms / 1000
if seconds < 1:
return f"{ms:.0f}ms"
if seconds < 60:
return f"{int(seconds)}s"
minutes = int(seconds // 60)
remaining_seconds = int(seconds % 60)
return f"{minutes}min{remaining_seconds}s"
def generate_html_report(processed_results, results_path, images, computer_spec):
html_content = ('<!DOCTYPE html>'
'<html lang="en">'
'<head>'
' <meta charset="UTF-8">'
' <meta name="viewport" content="width=device-width, initial-scale=1.0">'
' <title>Benchmarking Report</title>'
' <style>'
' body { font-family: Arial, sans-serif; }'
' table { border-collapse: collapse; margin-bottom: 20px; }'
' th, td { border: 1px solid #ddd; padding: 8px; text-align: center; }'
' th { background-color: #f2f2f2; }'
' </style>'
'</head>'
'<body>'
'<h2>Benchmarking Report</h2>'
f'<h3>Computer Specs</h3><pre>{computer_spec}</pre>')
image_json = json.loads(images)
for client, sizes in processed_results.items():
image_to_print = image_json.get(client, 'default')
if image_to_print == 'default':
with open('images.yaml', 'r') as f:
el_images = yaml.safe_load(f)["images"]
client_without_tag = client.split("_")[0]
image_to_print = el_images.get(client_without_tag, 'default')
html_content += f'<h3>{client.capitalize()} - {image_to_print}</h3>'
html_content += ('<table>'
'<thead>'
'<tr>'
'<th>Genesis File Size</th>'
'<th>Part</th>'
'<th>Max</th>'
'<th>p50</th>'
'<th>p95</th>'
'<th>p99</th>'
'<th>Min</th>'
'<th>Count</th>'
'</tr>'
'</thead>'
'<tbody>')
# Sorting sizes by numeric value (assumes sizes are in the format like "1M", "10M", etc.)
sorted_sizes = sorted(sizes.items(), key=lambda x: int(x[0].replace('M', '')))
for size, parts in sorted_sizes:
# Sorting parts by 'first' before 'second' and by run number
sorted_parts = sorted(parts.items(), key=lambda x: (x[0],))
for part, metrics in sorted_parts:
html_content += (f'<tr><td>{size}</td>'
f'<td>{part}</td>'
f'<td>{ms_to_readable_time(metrics["max"])}</td>'
f'<td>{ms_to_readable_time(metrics["p50"])}</td>'
f'<td>{ms_to_readable_time(metrics["p95"])}</td>'
f'<td>{ms_to_readable_time(metrics["p99"])}</td>'
f'<td>{ms_to_readable_time(metrics["min"])}</td>'
f'<td>{metrics["count"]}</td></tr>')
html_content += '</tbody></table>'
html_content += '</body></html>'
soup = BeautifulSoup(html_content, 'html.parser')
formatted_html = soup.prettify()
report_path = os.path.join(results_path, 'reports')
os.makedirs(report_path, exist_ok=True)
with open(os.path.join(report_path, 'speed.html'), 'w') as html_file:
html_file.write(formatted_html)
def main():
parser = argparse.ArgumentParser(description='Benchmark script')
parser.add_argument('--resultsPath', type=str, help='Path to gather the results', default='results/speed')
parser.add_argument('--images', type=str, help='Image values per each client',
default='{ "nethermind": "default", "besu": "default", "geth": "default", "reth": "default", "erigon": "default" }')
args = parser.parse_args()
results_path = args.resultsPath
images = args.images
reports_path = os.path.join(results_path, 'reports')
os.makedirs(reports_path, exist_ok=True)
# Get the computer spec
computer_spec_path = os.path.join(results_path, "computer_specs.txt")
if os.path.exists(computer_spec_path):
with open(computer_spec_path, 'r') as file:
computer_spec = file.read().strip()
else:
computer_spec = "Not available"
client_results = get_client_results(results_path)
print("Client Results:", client_results) # Add debug information
processed_results = process_client_results(client_results)
print("Processed Results:", processed_results) # Add debug information
generate_json_report(processed_results, results_path)
generate_html_report(processed_results, results_path, images, computer_spec)
print('Done!')
if __name__ == '__main__':
main()