-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalysis.py
142 lines (108 loc) · 4.29 KB
/
analysis.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
import json
import re
import matplotlib.pyplot as plt
import numpy as np
# Function to convert time units to seconds
def convert_to_seconds(time_str):
if time_str.endswith('ns'):
return float(time_str[:-2]) * 1e-9
elif time_str.endswith('µs'):
return float(time_str[:-2]) * 1e-6
elif time_str.endswith('ms'):
return float(time_str[:-2]) * 1e-3
elif time_str.endswith('s'):
return float(time_str[:-1])
return 0
def report(operation, time):
return f"{operation}: {time:.6f} seconds"
scenarios = {}
free_logs = []
hypernova = [[None] * 7 for _ in range(7)]
def process_logline(log):
fields = log.get("fields", {})
span = log.get("span", {})
scenario_name = None
time_seconds = convert_to_seconds(fields["time.busy"])
# A folding scheme scenario is one of our ancestors
for s in log.get("spans", []):
if s.get("name") == "scenario":
scenario_name = s.get("folding_scheme")
# Top level span
if not scenario_name:
folding_scheme = span.get("folding_scheme")
if folding_scheme is not None:
free_logs.append(report(f"{folding_scheme} total time", time_seconds))
hypernova_params = re.fullmatch(r"HyperNova<(\d),(\d)>", folding_scheme)
if hypernova_params:
hypernova[int(hypernova_params.groups()[0])][int(hypernova_params.groups()[1])] = time_seconds
else:
free_logs.append(report(span["name"], time_seconds))
return
# Within a folding scheme scenario
if scenario_name not in scenarios:
scenarios[scenario_name] = {
"Prepare folding": 0,
"Transform input": 0,
"Folding verification": 0,
"Proving": [],
"Input prep": [],
}
span_name = span.get("name")
if span_name == "Proving":
scenarios[scenario_name]["Proving"].append(time_seconds)
elif span_name == "Input prep":
scenarios[scenario_name]["Input prep"].append(time_seconds)
else:
scenarios[scenario_name][span_name] = time_seconds
def process_logs(file_path):
with open(file_path, 'r') as f:
for line in f:
process_logline(json.loads(line))
def print_results():
for log in free_logs:
print(log)
print()
for scenario_name, data in scenarios.items():
print("-" * 80)
print(f"Scenario: {scenario_name}")
print(report(" Prepare folding", data["Prepare folding"]))
print(report(" Transform input", data["Transform input"]))
print(report(" Folding verification", data["Folding verification"]))
print(f" Folding Steps:")
input_trans = data["Input prep"]
print(" Input preparation")
print(report(" Avg", sum(input_trans) / len(input_trans)))
print(report(" Min", min(input_trans)))
print(report(" Max", max(input_trans)))
proving_steps = data["Proving"]
print(" Proving")
print(report(" Avg", sum(proving_steps) / len(proving_steps)))
print(report(" Min", min(proving_steps)))
print(report(" Max", max(proving_steps)))
def draw_hn_plot():
global hypernova
hypernova = np.array(hypernova)[1:,1:]
data_np = np.array(hypernova, dtype=np.float64)
data_np = np.where(np.isnan(data_np), 0, data_np) # Replace None with 0 for better visualization
cmap = plt.cm.viridis
cmap.set_under('white') # Set background color for None
fig, ax = plt.subplots()
cax = ax.matshow(data_np, cmap=cmap, vmin=0.01)
fig.colorbar(cax)
for i in range(len(hypernova)):
for j in range(len(hypernova[i])):
if hypernova[i][j] is not None:
ax.text(j, i, f'{hypernova[i][j]:.2f}', va='center', ha='center', color='black')
# Set axis labels and title
ax.set_xlabel('ν (number of incoming CCCS instances)')
ax.set_ylabel('μ (number of running LCCCS instances)')
ax.set_xticks(np.arange(len(hypernova[0])))
ax.set_yticks(np.arange(len(hypernova)))
ax.set_xticklabels([f'{i}' for i in range(len(hypernova[0]))])
ax.set_yticklabels([f'{i}' for i in range(len(hypernova))])
plt.title("HyperNova multifold times")
# Show the plot
plt.show()
process_logs('out.log')
print_results()
draw_hn_plot()