add basic bench for trace-tef.multiproc

This commit is contained in:
Simon Cruanes 2024-08-16 15:46:35 -04:00
parent ba6861630d
commit 8697f53405
4 changed files with 71 additions and 0 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ _build
*.exe *.exe
perf.* perf.*
*.fxt *.fxt
*.tmp

View file

@ -10,6 +10,12 @@
(preprocess (pps ppx_trace)) (preprocess (pps ppx_trace))
(libraries trace.core trace-fuchsia)) (libraries trace.core trace-fuchsia))
(executable
(name trace_tldr)
(modules trace_tldr)
(preprocess (pps ppx_trace))
(libraries trace.core trace-tef.tldr))
(executable (executable
(name bench_fuchsia_write) (name bench_fuchsia_write)
(modules bench_fuchsia_write) (modules bench_fuchsia_write)

61
bench/trace_tldr.ml Normal file
View file

@ -0,0 +1,61 @@
module Trace = Trace_core
let ( let@ ) = ( @@ )
let work ~n () : unit =
for _i = 1 to n do
let@ _sp =
Trace.with_span ~__FILE__ ~__LINE__ "outer" ~data:(fun () ->
[ "i", `Int _i ])
in
for _k = 1 to 10 do
let@ _sp =
Trace.with_span ~__FILE__ ~__LINE__ "inner" ~data:(fun () ->
(* add some big data sometimes *)
if _i mod 100 = 0 && _k = 9 then
[ "s", `String (String.make 5000 '-') ]
else
[])
in
()
done;
if _i mod 1000 = 0 then Thread.yield ()
(* Thread.delay 1e-6 *)
done
let main ~n ~j ~child () : unit =
if child then
work ~n ()
else
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "parent" in
let cmd =
Printf.sprintf "%s --child -n=%d" (Filename.quote Sys.argv.(0)) n
in
let procs = Array.init j (fun _ -> Unix.open_process_in cmd) in
Array.iteri
(fun idx _ic ->
let@ _sp =
Trace.with_span ~__FILE__ ~__LINE__ "wait.child" ~data:(fun () ->
[ "i", `Int idx ])
in
ignore @@ Unix.close_process_in _ic)
procs
let () =
let@ () = Trace_tef_tldr.with_setup () in
let n = ref 10_000 in
let j = ref 4 in
let child = ref false in
let args =
[
"-n", Arg.Set_int n, " number of iterations";
"-j", Arg.Set_int j, " set number of workers";
"--child", Arg.Set child, " act as child process";
]
|> Arg.align
in
Arg.parse args ignore "bench1";
main ~n:!n ~j:!j ~child:!child ()

3
bench_tldr.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
DUNE_OPTS="--profile=release --display=quiet"
exec dune exec $DUNE_OPTS bench/trace_tldr.exe -- $@