@@ -43,17 +43,19 @@ def run(ruby:, ruby_description:)
4343 benchmark_entries = discover_benchmarks
4444 cmd_prefix = base_cmd ( ruby_description )
4545 env = benchmark_env ( ruby )
46+ caller_json_path = ENV [ "RESULT_JSON_PATH" ]
4647
4748 benchmark_entries . each_with_index do |entry , idx |
4849 puts ( "Running benchmark \" #{ entry . name } \" (#{ idx +1 } /#{ benchmark_entries . length } )" )
4950
50- result_json_path = File . join ( out_path , "temp#{ Process . pid } .json" )
51+ result_json_path = caller_json_path || File . join ( out_path , "temp#{ Process . pid } .json" )
5152 result = run_single_benchmark ( entry . script_path , result_json_path , ruby , cmd_prefix , env )
5253
5354 if result [ :success ]
54- bench_data [ entry . name ] = process_benchmark_result ( result_json_path , result [ :command ] )
55+ bench_data [ entry . name ] = process_benchmark_result ( result_json_path , result [ :command ] , delete_file : ! caller_json_path )
5556 else
5657 bench_failures [ entry . name ] = result [ :status ] . exitstatus
58+ FileUtils . rm_f ( result_json_path ) unless caller_json_path
5759 end
5860 end
5961
@@ -74,10 +76,10 @@ def setup_benchmark_directories
7476 end
7577 end
7678
77- def process_benchmark_result ( result_json_path , command )
79+ def process_benchmark_result ( result_json_path , command , delete_file : true )
7880 JSON . parse ( File . read ( result_json_path ) ) . tap do |json |
7981 json [ "command_line" ] = command
80- File . unlink ( result_json_path )
82+ File . unlink ( result_json_path ) if delete_file
8183 end
8284 end
8385
0 commit comments