@@ -85,150 +85,6 @@ let files () =
8585 in
8686 res
8787
88- let runs tool timeout output_dir max_tests =
89- let + files = files () in
90- let output_chan =
91- Fpath. (output_dir / " results" ) |> Fpath. to_string |> open_out
92- in
93- let fmt = Format. formatter_of_out_channel output_chan in
94- let pp x = Fmt. pf fmt x in
95- let files = List. sort Fpath. compare files in
96- let len = List. length files in
97- let results = ref Runs. empty in
98- List. iteri
99- (fun i file ->
100- let i = succ i in
101- if i < = max_tests then begin
102- Logs. app (fun m -> m " %a" (Run. pp_header (min len max_tests)) (i, file));
103- pp " %a@\n @[<v>" (Run. pp_header (min len max_tests)) (i, file);
104- let result =
105- Tool. fork_and_run_on_file ~i ~fmt ~output_dir ~file ~tool ~timeout
106- |> Utils. ok_or_fail
107- in
108- let result = { Run. i; file; res = result } in
109- results := Runs. add result ! results;
110- Logs. app (fun m -> m " %a@]" Runs. pp_quick_results ! results);
111- pp " %a@]@\n %!" Runs. pp_quick_results ! results
112- end )
113- files;
114- ! results
115-
116- let notify_finished runs timeout reference_name output_dir workers =
117- let open Cohttp in
118- let open Cohttp_lwt_unix in
119- let headers =
120- let headers = Header. init () in
121- Header. add_list headers
122- [ (" Content-type" , " application/json" ); (" User-Agent" , " Owibot/1.1" ) ]
123- in
124- let send url body =
125- let body = Cohttp_lwt.Body. of_string (Yojson. to_string body) in
126- Client. post ~body ~headers url
127- in
128- let head () =
129- let open Bos in
130- let cmd = Cmd. (v " git" % " rev-parse" % " --short" % " HEAD" ) in
131- let output = OS.Cmd. run_out ~err: OS.Cmd. err_run_out cmd in
132- match OS.Cmd. out_string ~trim: true output with
133- | Ok (stdout , (_ , `Exited 0 )) -> stdout
134- | Error (`Msg err ) ->
135- Fmt. epr " ERROR: %s@." err;
136- " unknown"
137- | Ok (stdout , (_ , (`Exited _ | `Signaled _ ))) ->
138- Fmt. epr " %s@\n WARN: Unable to fetch git HEAD@." stdout;
139- " unknown"
140- in
141- let text =
142- Fmt. str
143- " @[<v>Using:@;\
144- - Tool: `%s`@;\
145- - Timeout: `%F`@;\
146- - Output dir: `%a`@]@\n \
147- @\n \
148- Results:@\n \
149- @\n \
150- %a@\n \
151- @\n \
152- Wall clock stats (in seconds):@\n \
153- @\n \
154- %a@\n \
155- @\n \
156- User time stats (in seconds):@\n \
157- @\n \
158- %a@\n \
159- @\n \
160- System time stats (in seconds):@\n \
161- @\n \
162- %a@\n \
163- @\n \
164- Parallelism stats (ratio of parallelism / wall clock) (percentage is \
165- efficiency related to number of workers)(runs < 1s filtered out) :@\n \
166- @\n \
167- %a@\n \
168- @\n \
169- Memory stats (in MB):@\n \
170- @\n \
171- %a@."
172- reference_name timeout Fpath. pp output_dir Runs. pp_table_results runs
173- Runs. pp_table_wall_clock runs Runs. pp_table_user_time runs
174- Runs. pp_table_system_time runs
175- (Runs. pp_table_parallelism_ratio ~workers )
176- runs Runs. pp_table_memory runs
177- in
178- (* Notify on `ZULIP_WEBHOOK` *)
179- match Bos.OS.Env. var " ZULIP_WEBHOOK" with
180- | None -> Fmt. epr " %s" text
181- | Some url ->
182- let url = Uri. of_string url in
183- let title =
184- Fmt. str " Benchmark results (commit hash=%s) :octopus:" (head () )
185- in
186- let body =
187- (* Using Yojson just to ensure we're sending correct json *)
188- `Assoc
189- [ ( " blocks"
190- , `List
191- [ `Assoc
192- [ (" type" , `String " header" )
193- ; ( " text"
194- , `Assoc
195- [ (" type" , `String " plain_text" )
196- ; (" text" , `String title)
197- ; (" emoji" , `Bool true )
198- ] )
199- ]
200- ; `Assoc
201- [ (" type" , `String " section" )
202- ; ( " text"
203- , `Assoc
204- [ (" type" , `String " mrkdwn" ); (" text" , `String text) ]
205- )
206- ]
207- ] )
208- ]
209- in
210- let result, _ = Lwt_main. run @@ send url body in
211- let status = Response. status result in
212- Fmt. epr " Server responded: %s@." (Code. string_of_status status)
213-
214- let run tool timeout max_tests =
215- let * () =
216- match Bos.OS.Env. var Tool. tool_path_env_var_name with
217- | None -> Tool. check_if_available tool
218- | Some _ -> Ok ()
219- in
220- let t = Unix. localtime @@ Unix. gettimeofday () in
221- let reference_name = Tool. to_reference_name tool in
222- let filename =
223- Fmt. str " results-testcomp-%s-%d-%02d-%02d_%02dh%02dm%02ds/" reference_name
224- (1900 + t.tm_year) (1 + t.tm_mon) t.tm_mday t.tm_hour t.tm_min t.tm_sec
225- in
226- let output_dir = Fpath. v filename in
227- let _ : bool =
228- Bos.OS.Dir. create ~path: true ~mode: 0o755 output_dir |> Utils. ok_or_fail
229- in
230- let runs = runs tool timeout output_dir max_tests in
231- let runs = Utils. ok_or_fail runs in
232- let workers = Tool. get_number_of_workers tool in
233- notify_finished runs timeout reference_name output_dir workers;
234- Utils. gen_full_report runs output_dir reference_name
88+ let run tool timeout max_test =
89+ let files = Utils. ok_or_fail (files () ) in
90+ Bench. run tool timeout max_test files
0 commit comments