mirror of
https://github.com/ocaml-tracing/ocaml-trace.git
synced 2026-03-08 03:47:57 -04:00
wip: test for fuchsia
This commit is contained in:
parent
7405e3ae1b
commit
7cc16bc0b8
2 changed files with 53 additions and 0 deletions
5
test/fuchsia/dune
Normal file
5
test/fuchsia/dune
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
(test
|
||||||
|
(name t1)
|
||||||
|
(package trace-fuchsia)
|
||||||
|
(modules t1)
|
||||||
|
(libraries trace trace-fuchsia))
|
||||||
48
test/fuchsia/t1.ml
Normal file
48
test/fuchsia/t1.ml
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
let run () =
|
||||||
|
Trace.set_process_name "main";
|
||||||
|
Trace.set_thread_name "t1";
|
||||||
|
|
||||||
|
let n = ref 0 in
|
||||||
|
|
||||||
|
for _i = 1 to 50 do
|
||||||
|
Trace.with_span ~__FILE__ ~__LINE__ "outer.loop" @@ fun _sp ->
|
||||||
|
let pseudo_async_sp =
|
||||||
|
Trace.enter_manual_span ~parent:None ~__FILE__ ~__LINE__ "fake_sleep"
|
||||||
|
in
|
||||||
|
|
||||||
|
for _j = 2 to 5 do
|
||||||
|
incr n;
|
||||||
|
Trace.with_span ~__FILE__ ~__LINE__ "inner.loop" @@ fun _sp ->
|
||||||
|
Trace.messagef (fun k -> k "hello %d %d" _i _j);
|
||||||
|
Trace.message "world";
|
||||||
|
Trace.counter_int "n" !n;
|
||||||
|
|
||||||
|
Trace.add_data_to_span _sp [ "i", `Int _i ];
|
||||||
|
|
||||||
|
if _j = 2 then (
|
||||||
|
Trace.add_data_to_span _sp [ "j", `Int _j ];
|
||||||
|
let _sp =
|
||||||
|
Trace.enter_manual_span
|
||||||
|
~parent:(Some (Trace.ctx_of_span pseudo_async_sp))
|
||||||
|
~flavor:
|
||||||
|
(if _i mod 3 = 0 then
|
||||||
|
`Sync
|
||||||
|
else
|
||||||
|
`Async)
|
||||||
|
~__FILE__ ~__LINE__ "sub-sleep"
|
||||||
|
in
|
||||||
|
|
||||||
|
(* fake micro sleep *)
|
||||||
|
Thread.delay 0.005;
|
||||||
|
Trace.exit_manual_span _sp
|
||||||
|
) else if _j = 3 then (
|
||||||
|
(* pretend some task finished. Note that this is not well scoped wrt other spans. *)
|
||||||
|
Trace.add_data_to_manual_span pseudo_async_sp [ "slept", `Bool true ];
|
||||||
|
Trace.exit_manual_span pseudo_async_sp
|
||||||
|
)
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
let () =
|
||||||
|
Trace_tef.Private_.mock_all_ ();
|
||||||
|
Trace_tef.with_setup ~out:`Stdout () @@ fun () -> run ()
|
||||||
Loading…
Add table
Reference in a new issue