@@ -67,6 +67,28 @@ class BenchmarkDriver(object):
67
67
else 'O' )
68
68
return os .path .join (self .args .tests , "Benchmark_" + suffix )
69
69
70
+ def _git (self , cmd ):
71
+ """Execute the Git command in the `swift-repo`."""
72
+ return self ._invoke (
73
+ ('git -C {0} ' .format (self .args .swift_repo ) + cmd ).split ()).strip ()
74
+
75
+ @property
76
+ def log_file (self ):
77
+ """Full path to log file.
78
+
79
+ If `swift-repo` is set, log file is tied to Git branch and revision.
80
+ """
81
+ if not self .args .output_dir :
82
+ return None
83
+ log_dir = self .args .output_dir
84
+ harness_name = os .path .basename (self .test_harness )
85
+ suffix = '-' + time .strftime ('%Y%m%d%H%M%S' , time .localtime ())
86
+ if self .args .swift_repo :
87
+ log_dir = os .path .join (
88
+ log_dir , self ._git ('rev-parse --abbrev-ref HEAD' )) # branch
89
+ suffix += '-' + self ._git ('rev-parse --short HEAD' ) # revision
90
+ return os .path .join (log_dir , harness_name + suffix + '.log' )
91
+
70
92
@property
71
93
def _cmd_list_benchmarks (self ):
72
94
# Use tab delimiter for easier parsing to override the default comma.
@@ -377,52 +399,17 @@ class BenchmarkDoctor(object):
377
399
return 0
378
400
379
401
380
- def get_current_git_branch (git_repo_path ):
381
- """Return the selected branch for the repo `git_repo_path`"""
382
- return subprocess .check_output (
383
- ['git' , '-C' , git_repo_path , 'rev-parse' ,
384
- '--abbrev-ref' , 'HEAD' ], stderr = subprocess .STDOUT ).strip ()
385
-
386
-
387
- def get_git_head_ID (git_repo_path ):
388
- """Return the short identifier for the HEAD commit of the repo
389
- `git_repo_path`"""
390
- return subprocess .check_output (
391
- ['git' , '-C' , git_repo_path , 'rev-parse' ,
392
- '--short' , 'HEAD' ], stderr = subprocess .STDOUT ).strip ()
393
-
394
-
395
- def log_results (log_directory , driver , formatted_output , swift_repo = None ):
396
- """Log `formatted_output` to a branch specific directory in
397
- `log_directory`
398
- """
399
- try :
400
- branch = get_current_git_branch (swift_repo )
401
- except (OSError , subprocess .CalledProcessError ):
402
- branch = None
403
- try :
404
- head_ID = '-' + get_git_head_ID (swift_repo )
405
- except (OSError , subprocess .CalledProcessError ):
406
- head_ID = ''
407
- timestamp = time .strftime ("%Y%m%d%H%M%S" , time .localtime ())
408
- if branch :
409
- output_directory = os .path .join (log_directory , branch )
410
- else :
411
- output_directory = log_directory
412
- driver_name = os .path .basename (driver )
402
+ def log_results (log_file , formatted_output ):
413
403
try :
414
- os .makedirs (output_directory )
404
+ os .makedirs (os . path . dirname ( log_file ) )
415
405
except OSError :
416
406
pass
417
- log_file = os .path .join (output_directory ,
418
- driver_name + '-' + timestamp + head_ID + '.log' )
419
407
print ('Logging results to: %s' % log_file )
420
408
with open (log_file , 'w' ) as f :
421
409
f .write (formatted_output )
422
410
423
411
424
- def run_benchmarks (driver ,
425
- log_directory = None , swift_repo = None ):
412
+ def run_benchmarks (driver ):
426
413
"""Run perf tests individually and return results in a format that's
427
414
compatible with `LogParser`.
428
415
"""
@@ -433,11 +420,12 @@ def run_benchmarks(driver,
433
420
# that runs the tests.
434
421
os .environ ["SWIFT_DETERMINISTIC_HASHING" ] = "1"
435
422
423
+ log = driver .log_file
436
424
output = []
437
425
headings = ['#' , 'TEST' , 'SAMPLES' , 'MIN(μs)' , 'MAX(μs)' , 'MEAN(μs)' ,
438
426
'SD(μs)' , 'MEDIAN(μs)' , 'MAX_RSS(B)' ]
439
427
line_format = '{:>3} {:<25} {:>7} {:>7} {:>7} {:>8} {:>6} {:>10} {:>10}'
440
- if log_directory :
428
+ if log :
441
429
print (line_format .format (* headings ))
442
430
else :
443
431
print (',' .join (headings ))
@@ -446,7 +434,7 @@ def run_benchmarks(driver,
446
434
test_output = map (str , [
447
435
r .test_num , r .name , r .num_samples , r .min , r .max , int (r .mean ),
448
436
int (r .sd ), r .median , r .max_rss ])
449
- if log_directory :
437
+ if log :
450
438
print (line_format .format (* test_output ))
451
439
else :
452
440
print (',' .join (test_output ))
@@ -456,22 +444,18 @@ def run_benchmarks(driver,
456
444
formatted_output = '\n ' .join ([',' .join (l ) for l in output ])
457
445
totals = ['Totals' , str (len (driver .tests ))]
458
446
totals_output = '\n \n ' + ',' .join (totals )
459
- if log_directory :
447
+ if log :
460
448
print (line_format .format (* (['' ] + totals + (['' ] * 6 ))))
461
449
else :
462
450
print (totals_output [1 :])
463
451
formatted_output += totals_output
464
- if log_directory :
465
- log_results (log_directory , driver .test_harness , formatted_output ,
466
- swift_repo )
452
+ if log :
453
+ log_results (log , formatted_output )
467
454
return formatted_output
468
455
469
456
470
457
def run (args ):
471
- run_benchmarks (
472
- BenchmarkDriver (args ),
473
- log_directory = args .output_dir ,
474
- swift_repo = args .swift_repo )
458
+ run_benchmarks (BenchmarkDriver (args ))
475
459
return 0
476
460
477
461
@@ -491,10 +475,10 @@ def compare_logs(compare_script, new_log, old_log, log_dir, opt):
491
475
492
476
def compare (args ):
493
477
log_dir = args .log_dir
494
- swift_repo = args .swift_repo
495
478
compare_script = args .compare_script
496
479
baseline_branch = args .baseline_branch
497
- current_branch = get_current_git_branch (swift_repo )
480
+ current_branch = \
481
+ BenchmarkDriver (args , tests = ['' ])._git ('rev-parse --abbrev-ref HEAD' )
498
482
current_branch_dir = os .path .join (log_dir , current_branch )
499
483
baseline_branch_dir = os .path .join (log_dir , baseline_branch )
500
484
0 commit comments