-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_performance_report.py
executable file
·102 lines (75 loc) · 2.97 KB
/
generate_performance_report.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
#!/usr/bin/env python3
import git
import os
import matplotlib.pyplot as plt
perf_report_path = r'./performance_report/'
perf_test_path = r'../tests/performance_tests/Build/Linux/Release/NeuralNetwork_performance_tests'
perf_test_tmp_result_path = perf_report_path + r'tmp_result.txt'
perf_test_results_path = perf_report_path + r'results/'
perf_test_plots_path = perf_report_path + r'plots/'
plt.style.use('dark_background')
os.system(r'./build_release_sse.sh')
repo = git.Repo('./..')
repo_diff = repo.index.diff(None)
if len(repo_diff) > 0:
print('Please commit your changes before running this script. Uncommited changes found in files:')
for diff in repo_diff:
print(f' {diff.a_path}')
exit(1)
commit_hash = repo.head.commit.hexsha
print(f'Commit hash = {commit_hash}')
if not(os.path.isdir(perf_report_path)):
os.mkdir(perf_report_path)
os.system(f'{perf_test_path} > {perf_test_tmp_result_path}')
print('Gathering test results.')
results = {}
with open(perf_test_tmp_result_path, 'r') as tmp_result_file:
for line in tmp_result_file:
line_split = line.split()
if line_split[0][:3] == 'BM_':
results[line_split[0]] = f'{line_split[1]} {line_split[2]}'
os.remove(perf_test_tmp_result_path)
if not(os.path.isdir(perf_test_results_path)):
os.mkdir(perf_test_results_path)
for key, value in results.items():
print(f' test: {key}')
with open(os.path.join(perf_test_results_path, key + '.txt'), 'a+') as result_file:
result_file.write(f'{commit_hash} {value}\n')
all_tests = []
for _, _, fnames in os.walk(perf_test_results_path):
for fname in fnames:
all_tests.append(fname.split('.')[0])
break
if not(os.path.isdir(perf_test_plots_path)):
os.mkdir(perf_test_plots_path)
all_commits = [c.hexsha for c in repo.iter_commits()]
print('Preparing plots.')
for test in all_tests:
results = {c: None for c in all_commits[::-1]}
with open(os.path.join(perf_test_results_path, test + '.txt')) as result_file:
for line in result_file:
commit, time, _ = line.split()
results[commit] = int(time)
x = []
y = []
for commit, time in results.items():
if time is not None:
x.append(commit[:6])
y.append(time)
fig = plt.figure(figsize=(12, 3), facecolor=(13./255, 17./255, 23./255))
ax = plt.gca()
ax.set_facecolor((13./255, 17./255, 23./255))
plt.plot(x, y, color='aqua')
plt.xticks(rotation=90)
plt.ylim(0, None)
plt.title(test)
plt.grid('both')
plt.savefig(os.path.join(perf_test_plots_path, test + '.png'), dpi=300, bbox_inches='tight', facecolor=fig.get_facecolor())
plt.clf()
remote_url = repo.remotes.origin.url
print(remote_url)
print('Creating report.')
with open(os.path.join(perf_report_path, 'report.md'), 'w') as report_file:
for test in sorted(all_tests):
report_file.write(f'![{test}]({remote_url}/blob/master/Build/{perf_test_plots_path}/{test}.png)\n')
print('All done.')