37
37
import random
38
38
import numpy as np
39
39
40
+ from pandas import DataFrame
41
+
42
+ from suite import REPO_PATH
43
+
40
44
DEFAULT_MIN_DURATION = 0.01
45
+ HEAD_COL = "t_head"
41
46
42
47
parser = argparse .ArgumentParser (description = 'Use vbench to generate a report comparing performance between two commits.' )
43
- parser .add_argument ('-a' , '--auto' ,
44
- help = 'Execute a run using the defaults for the base and target commits.' ,
48
+ parser .add_argument ('-H' , '--head' ,
49
+ help = 'Execute vbenches using the currently checked out copy.' ,
50
+ dest = 'head' ,
45
51
action = 'store_true' ,
46
52
default = False )
47
53
parser .add_argument ('-b' , '--base-commit' ,
77
83
78
84
79
85
def get_results_df (db , rev ):
80
- from pandas import DataFrame
81
86
"""Takes a git commit hash and returns a Dataframe of benchmark results
82
87
"""
83
88
bench = DataFrame (db .get_benchmarks ())
@@ -93,47 +98,16 @@ def get_results_df(db, rev):
93
98
def prprint (s ):
94
99
print ("*** %s" % s )
95
100
96
- def main ( ):
97
- from pandas import DataFrame
101
+ def profile_comparative ( benchmarks ):
102
+
98
103
from vbench .api import BenchmarkRunner
99
104
from vbench .db import BenchmarkDB
100
105
from vbench .git import GitRepo
101
- from suite import REPO_PATH , BUILD , DB_PATH , PREPARE , dependencies , benchmarks
102
-
103
- # GitRepo wants exactly 7 character hash?
104
- args .base_commit = args .base_commit [:7 ]
105
- if args .target_commit :
106
- args .target_commit = args .target_commit [:7 ]
107
-
108
- if not args .log_file :
109
- args .log_file = os .path .abspath (
110
- os .path .join (REPO_PATH , 'vb_suite.log' ))
111
-
112
- if args .outdf :
113
- # not bullet-proof but enough for us
114
- if os .path .sep not in args .outdf :
115
- args .outdf = os .path .join (os .curdir , args .outdf )
116
-
117
- if args .log_file :
118
- # not bullet-proof but enough for us
119
- if os .path .sep not in args .log_file :
120
- args .log_file = os .path .join (os .curdir , args .log_file )
121
-
122
- random .seed (args .seed )
123
- np .random .seed (args .seed )
124
-
106
+ from suite import BUILD , DB_PATH , PREPARE , dependencies
125
107
TMP_DIR = tempfile .mkdtemp ()
126
- prprint ("TMP_DIR = %s" % TMP_DIR )
127
- prprint ("LOG_FILE = %s\n " % args .log_file )
128
-
129
- saved_dir = os .path .curdir
130
- # move away from the pandas root dit, to avoid possible import
131
- # surprises
132
- os .chdir (os .path .dirname (os .path .abspath (__file__ )))
133
-
134
- benchmarks = [x for x in benchmarks if re .search (args .regex ,x .name )]
135
108
136
109
try :
110
+
137
111
prprint ("Opening DB at '%s'...\n " % DB_PATH )
138
112
db = BenchmarkDB (DB_PATH )
139
113
@@ -184,7 +158,7 @@ def main():
184
158
totals = DataFrame (dict (t_head = head_res ['timing' ],
185
159
t_baseline = baseline_res ['timing' ],
186
160
ratio = ratio ,
187
- name = baseline_res .name ), columns = ["t_head" , "t_baseline" , "ratio" , "name" ])
161
+ name = baseline_res .name ), columns = [HEAD_COL , "t_baseline" , "ratio" , "name" ])
188
162
totals = totals .ix [totals .t_head > args .min_duration ]
189
163
# ignore below threshold
190
164
totals = totals .dropna (
@@ -225,9 +199,67 @@ def main():
225
199
finally :
226
200
# print("Disposing of TMP_DIR: %s" % TMP_DIR)
227
201
shutil .rmtree (TMP_DIR )
228
- os .chdir (saved_dir )
229
202
203
+ def profile_head (benchmarks ):
204
+ results = []
205
+ s = ""
206
+ for b in benchmarks :
207
+ d = b .run ()
208
+ d .update (dict (name = b .name ))
209
+ results .append (dict (name = d ['name' ],timing = d ['timing' ]))
210
+ msg = "{name:<40}: {timing:> 10.4f} [ms]"
211
+ line = msg .format (name = results [- 1 ]['name' ], timing = results [- 1 ]['timing' ])
212
+ print (line )
213
+ s += line + "\n "
214
+
215
+ logfile = open (args .log_file , 'w' )
216
+ logfile .write (s )
217
+ logfile .close ()
218
+
219
+ if args .outdf :
220
+ prprint ("The results DataFrame was written to '%s'\n " % args .outdf )
221
+ DataFrame (results ,columns = ["name" ,HEAD_COL ]).save (args .outdf )
222
+
223
+ def main ():
224
+ from suite import benchmarks
225
+ # GitRepo wants exactly 7 character hash?
226
+ if args .base_commit :
227
+ args .base_commit = args .base_commit [:7 ]
228
+ if args .target_commit :
229
+ args .target_commit = args .target_commit [:7 ]
230
+
231
+ if not args .log_file :
232
+ args .log_file = os .path .abspath (
233
+ os .path .join (REPO_PATH , 'vb_suite.log' ))
234
+
235
+ if args .outdf :
236
+ # not bullet-proof but enough for us
237
+ if os .path .sep not in args .outdf :
238
+ args .outdf = os .path .join (os .curdir , args .outdf )
239
+
240
+ if args .log_file :
241
+ # not bullet-proof but enough for us
242
+ if os .path .sep not in args .log_file :
243
+ args .log_file = os .path .join (os .curdir , args .log_file )
244
+
245
+ random .seed (args .seed )
246
+ np .random .seed (args .seed )
247
+
248
+ prprint ("LOG_FILE = %s\n " % args .log_file )
249
+
250
+ saved_dir = os .path .curdir
251
+ # move away from the pandas root dit, to avoid possible import
252
+ # surprises
253
+ os .chdir (os .path .dirname (os .path .abspath (__file__ )))
254
+
255
+ benchmarks = [x for x in benchmarks if re .search (args .regex ,x .name )]
256
+
257
+ if args .head :
258
+ profile_head (benchmarks )
259
+ else :
260
+ profile_comparative (benchmarks )
230
261
262
+ os .chdir (saved_dir )
231
263
232
264
# hack , vbench.git ignores some commits, but we
233
265
# need to be able to reference any commit.
@@ -279,7 +311,7 @@ def inner(repo_path):
279
311
280
312
if __name__ == '__main__' :
281
313
args = parser .parse_args ()
282
- if not args .auto and (not args .base_commit and not args .target_commit ):
314
+ if not args .head and (not args .base_commit and not args .target_commit ):
283
315
parser .print_help ()
284
316
else :
285
317
main ()
0 commit comments