@@ -43,9 +43,11 @@ def main(argv):
43
43
parser .add_argument ('--commit-list' , type = argparse .FileType ('r' ), default = sys .stdin ,
44
44
help = 'Path to a file containing a whitespace separated list of commits to test. '
45
45
'By default, this is read from standard input.' )
46
- parser .add_argument ('--overwrite' , action = 'store_true' ,
47
- help = 'When the data for a commit already exists in the output directory, the tool normally skips it. '
48
- 'This option instructs the tool to generate the data and overwrite it in the output directory.' )
46
+ parser .add_argument ('--existing' , type = str , choices = ['skip' , 'overwrite' , 'append' ], default = 'skip' ,
47
+ help = 'This option instructs what to do when data for a commit already exists in the output directory. '
48
+ 'Selecting "skip" instructs the tool to skip generating data for a commit that already has data, '
49
+ '"overwrite" will overwrite the existing data with the newly-generated one, and "append" will '
50
+ 'append the new data to the existing one. By default, the tool uses "skip".' )
49
51
parser .add_argument ('lit_options' , nargs = argparse .REMAINDER ,
50
52
help = 'Optional arguments passed to lit when running the tests. Should be provided last and '
51
53
'separated from other arguments with a `--`.' )
@@ -70,14 +72,11 @@ def main(argv):
70
72
commit = resolve_commit (args .git_repo , commit ) # resolve e.g. HEAD to a real SHA
71
73
72
74
output_file = args .output / (commit + '.lnt' )
73
- if output_file .exists ():
74
- if args .overwrite :
75
- logging .info (f'Will overwrite data for commit { commit } in { output_file } ' )
76
- else :
77
- logging .info (f'Data for commit { commit } already exists in { output_file } , skipping' )
78
- continue
75
+ if output_file .exists () and args .existing == 'skip' :
76
+ logging .info (f'Skipping { commit } which already has data in { output_file } ' )
77
+ continue
79
78
else :
80
- logging .info (f'Benchmarking commit { commit } ' )
79
+ logging .info (f'Benchmarking { commit } ' )
81
80
82
81
with tempfile .TemporaryDirectory () as build_dir :
83
82
test_cmd = [PARENT_DIR / 'test-at-commit' , '--git-repo' , args .git_repo ,
@@ -92,8 +91,15 @@ def main(argv):
92
91
93
92
subprocess .call (test_cmd )
94
93
output_file .parent .mkdir (parents = True , exist_ok = True )
95
- consolidate_cmd = [(PARENT_DIR / 'consolidate-benchmarks' ), build_dir , '--output' , output_file ]
96
- subprocess .check_call (consolidate_cmd )
94
+ if output_file .exists () and args .existing == 'append' :
95
+ logging .info (f'Appending to existing data for { commit } ' )
96
+ mode = 'a'
97
+ else :
98
+ assert args .existing == 'overwrite'
99
+ logging .info (f'Overwriting existing data for { commit } ' )
100
+ mode = 'w'
101
+ with open (output_file , mode ) as out :
102
+ subprocess .check_call ([(PARENT_DIR / 'consolidate-benchmarks' ), build_dir ], stdout = out )
97
103
98
104
if __name__ == '__main__' :
99
105
main (sys .argv [1 :])
0 commit comments