-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplot_results.py
More file actions
56 lines (42 loc) · 2.18 KB
/
plot_results.py
File metadata and controls
56 lines (42 loc) · 2.18 KB
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
import seaborn as sns
import pandas as pd
import glob
import matplotlib.pyplot as plt
# This function plots the length distribution using the results found in output_path.
# it outputs the result of this plotting into `output_path`/trace_length_dist.pdf as a seaborn histogram
def plot_trace_length_dist(output_path):
log_files = glob.glob(f"{output_path}/**/magic*.fpvm_log", recursive=True)
parsed_data = []
for log in log_files:
with open(log, 'r') as file:
benchmark = log.split('/')[2]
for line in file:
if "TRACE BEGIN" in line:
# Split the line based on spaces
data = line.replace('(', ' ').replace(')',' ').split()
# Find the indices of instr_count and trace_count keywords
instr_index = data.index("instr_count") + 1
trace_index = data.index("trace_count") + 1
# Try converting values to integers, handle exceptions
try:
instr_count = int(data[instr_index])
trace_count = int(data[trace_index])
parsed_data.append((benchmark, instr_count, trace_count))
except (ValueError, IndexError):
print(data)
# Log or handle potential errors during conversion
pass
# df = pd.DataFrame(parsed_data, columns=['benchmark', 'length', 'count'])
# sns.scatterplot(df, x='length', y='count', hue='benchmark')
# plt.savefig(f'{output_path}/trace_length_dist.pdf', format='pdf')
#
# return
csv_files = glob.glob(f"{output_path}/**/*.tracehist.txt", recursive=True)
print(csv_files)
df = pd.concat([pd.read_csv(file, sep='\t') for file in csv_files], ignore_index=True).sort_values(by='length')
sns.lineplot(df, x='length', y='cumprob', hue='benchmark')
# sns.histplot(df, x='length', y='count', hue='benchmark', cumulative=True)
print(df)
plt.savefig(f'{output_path}/trace_length_dist.pdf', format='pdf') # Replace 'my_seaborn_plot.pdf' with your desired filename
pass
plot_trace_length_dist('results/latest')