-
Notifications
You must be signed in to change notification settings - Fork 1
/
line_hit_frequency.py
84 lines (66 loc) · 2.24 KB
/
line_hit_frequency.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
import matplotlib.pyplot as plt
from utils import load_summary
from functools import reduce
import operator
import argparse
def load_experiment(experiment_path: str) -> tuple[str, int, dict]:
summary = load_summary(experiment_path)
return (
summary["experiment_name"],
summary["nb_runs"],
summary["executed_lines_counter"],
)
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--no-interactive", action="store_true")
parser.add_argument("experiments", nargs="+")
args = parser.parse_args()
all_experiment_name, all_nb_runs, all_executed_lines_counter = zip(
*(load_experiment(experiment_path) for experiment_path in args.experiments)
)
total_nb_runs = sum(all_nb_runs)
lines = sorted(
reduce(
operator.or_,
(
executed_lines_counter.keys()
for executed_lines_counter in all_executed_lines_counter
),
),
key=lambda line: int(line),
)
fig, ax = plt.subplots(figsize=(5, 10))
left = [0] * len(lines)
for experiment_name, executed_lines_counter in zip(
all_experiment_name, all_executed_lines_counter
):
sorted_line_hit_frequencies = [
executed_lines_counter[line] / total_nb_runs for line in lines
]
ax.barh(
lines,
sorted_line_hit_frequencies,
label=experiment_name,
left=left,
)
left = [sum(x) for x in zip(left, sorted_line_hit_frequencies)]
ax.set_ylabel("Line number")
ax.set_xlabel("Line hit frequency")
ax.set_ylim((len(lines) * len(all_experiment_name)) / -20, len(lines) + 5)
ax.invert_yaxis()
experiment_names = " and ".join(all_experiment_name)
title = f"Line hit frequency of {experiment_names}"
fig.canvas.manager.set_window_title(title)
plt.xticks([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1])
plt.yticks(range(0, len(lines), len(lines) // 25))
plt.legend(loc="upper right")
if args.no_interactive:
plt.savefig(
title.replace(" ", "_") + ".png",
dpi=300,
bbox_inches="tight",
)
else:
plt.show()
if __name__ == "__main__":
main()