@@ -43,9 +43,11 @@ def main(argv):
4343 parser .add_argument ('--commit-list' , type = argparse .FileType ('r' ), default = sys .stdin ,
4444 help = 'Path to a file containing a whitespace separated list of commits to test. '
4545 '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".' )
4951 parser .add_argument ('lit_options' , nargs = argparse .REMAINDER ,
5052 help = 'Optional arguments passed to lit when running the tests. Should be provided last and '
5153 'separated from other arguments with a `--`.' )
@@ -70,14 +72,11 @@ def main(argv):
7072 commit = resolve_commit (args .git_repo , commit ) # resolve e.g. HEAD to a real SHA
7173
7274 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
7978 else :
80- logging .info (f'Benchmarking commit { commit } ' )
79+ logging .info (f'Benchmarking { commit } ' )
8180
8281 with tempfile .TemporaryDirectory () as build_dir :
8382 test_cmd = [PARENT_DIR / 'test-at-commit' , '--git-repo' , args .git_repo ,
@@ -92,8 +91,15 @@ def main(argv):
9291
9392 subprocess .call (test_cmd )
9493 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 )
97103
98104if __name__ == '__main__' :
99105 main (sys .argv [1 :])
0 commit comments