forked from aws/aws-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperfcmp
executable file
·152 lines (123 loc) · 4.83 KB
/
perfcmp
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
#!/usr/bin/env python
"""Compare 2 perf runs.
To use, specify the local directories that contain
the run information::
$ ./perfcmp /results/2016-01-01-1111/ /results/2016-01-01-2222/
"""
import os
import json
import argparse
from colorama import Fore, Style
from tabulate import tabulate
class RunComparison(object):
MEMORY_FIELDS = ['average_memory', 'max_memory']
TIME_FIELDS = ['total_time']
# Fields that aren't memory or time fields, they require
# no special formatting.
OTHER_FIELDS = ['average_cpu']
def __init__(self, old_summary, new_summary):
self.old_summary = old_summary
self.new_summary = new_summary
def iter_field_names(self):
for field in self.TIME_FIELDS + self.MEMORY_FIELDS + self.OTHER_FIELDS:
yield field
def old(self, field):
value = self.old_summary[field]
return self._format(field, value)
def old_suffix(self, field):
value = self.old_summary[field]
return self._format_suffix(field, value)
def new_suffix(self, field):
value = self.new_summary[field]
return self._format_suffix(field, value)
def _format_suffix(self, field, value):
if field in self.TIME_FIELDS:
return 'sec'
elif field in self.OTHER_FIELDS:
return ''
else:
# The suffix depends on the actual value.
return self._human_readable_size(value)[1]
def old_stddev(self, field):
real_field = 'std_dev_%s' % field
return self.old(real_field)
def new(self, field):
value = self.new_summary[field]
return self._format(field, value)
def new_stddev(self, field):
real_field = 'std_dev_%s' % field
return self.new(real_field)
def _format(self, field, value):
if field.startswith('std_dev_'):
field = field[len('std_dev_'):]
if field in self.MEMORY_FIELDS:
return self._human_readable_size(value)[0]
elif field in self.TIME_FIELDS:
return '%-3.2f' % value
else:
return '%.2f' % value
def _human_readable_size(self, value):
hummanize_suffixes = ('KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB')
base = 1024
bytes_int = float(value)
if bytes_int == 1:
return '1 Byte'
elif bytes_int < base:
return '%d Bytes' % bytes_int
for i, suffix in enumerate(hummanize_suffixes):
unit = base ** (i+2)
if round((bytes_int / unit) * base) < base:
return ['%.2f' % (base * bytes_int / unit), suffix]
def diff_percent(self, field):
diff_percent = (
(self.new_summary[field] - self.old_summary[field]) /
float(self.old_summary[field])) * 100
return diff_percent
def compare_runs(old_dir, new_dir):
for dirname in os.listdir(old_dir):
old_run_dir = os.path.join(old_dir, dirname)
new_run_dir = os.path.join(new_dir, dirname)
if not os.path.isdir(old_run_dir):
continue
old_summary = get_summary(old_run_dir)
new_summary = get_summary(new_run_dir)
comp = RunComparison(old_summary, new_summary)
header = [Style.BRIGHT + dirname + Style.RESET_ALL,
Style.BRIGHT + 'old' + Style.RESET_ALL,
# Numeric suffix (MiB, GiB, sec).
'',
'std_dev',
Style.BRIGHT + 'new' + Style.RESET_ALL,
# Numeric suffix (MiB, GiB, sec).
'',
'std_dev',
Style.BRIGHT + 'delta' + Style.RESET_ALL]
rows = []
for field in comp.iter_field_names():
row = [field, comp.old(field), comp.old_suffix(field),
comp.old_stddev(field), comp.new(field),
comp.new_suffix(field), comp.new_stddev(field)]
diff_percent = comp.diff_percent(field)
diff_percent_str = '%.2f%%' % diff_percent
if diff_percent < 0:
diff_percent_str = (
Fore.GREEN + diff_percent_str + Style.RESET_ALL)
else:
diff_percent_str = (
Fore.RED + diff_percent_str + Style.RESET_ALL)
row.append(diff_percent_str)
rows.append(row)
print(tabulate(rows, headers=header, tablefmt='plain'))
print('')
def get_summary(benchmark_dir):
summary_json = os.path.join(benchmark_dir, 'summary.json')
with open(summary_json) as f:
return json.load(f)
def main():
parser = argparse.ArgumentParser(description='__doc__')
parser.add_argument('oldrunid', help='Path to old run idir')
parser.add_argument('newrunid', help='Local to new run dir')
args = parser.parse_args()
compare_runs(args.oldrunid, args.newrunid)
if __name__ == '__main__':
main()