mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 03:47:59 -04:00
test: add -j and other options to emit1
This commit is contained in:
parent
b5d3d8cbbb
commit
bac633d09d
1 changed files with 53 additions and 11 deletions
|
|
@ -1,4 +1,5 @@
|
|||
module T = Opentelemetry
|
||||
module Atomic = Opentelemetry_atomic.Atomic
|
||||
|
||||
let spf = Printf.sprintf
|
||||
|
||||
|
|
@ -8,31 +9,36 @@ let sleep_inner = ref 0.1
|
|||
|
||||
let sleep_outer = ref 2.0
|
||||
|
||||
let num_sleep = ref 0
|
||||
let n_jobs = ref 1
|
||||
|
||||
let run () =
|
||||
Printf.printf "collector is on %S\n%!" (Opentelemetry_client_ocurl.get_url ());
|
||||
T.GC_metrics.basic_setup ();
|
||||
let num_sleep = Atomic.make 0
|
||||
|
||||
T.Metrics_callbacks.register (fun () ->
|
||||
T.Metrics.[ sum ~name:"num-sleep" ~is_monotonic:true [ int !num_sleep ] ]);
|
||||
let stress_alloc_ = ref true
|
||||
|
||||
let stop = Atomic.make false
|
||||
|
||||
let num_tr = Atomic.make 0
|
||||
|
||||
let run_job () =
|
||||
let@ () = Fun.protect ~finally:(fun () -> Atomic.set stop true) in
|
||||
let i = ref 0 in
|
||||
while true do
|
||||
while not @@ Atomic.get stop do
|
||||
let@ scope =
|
||||
Atomic.incr num_tr;
|
||||
T.Trace.with_ ~kind:T.Span.Span_kind_producer "loop.outer"
|
||||
~attrs:[ "i", `Int !i ]
|
||||
in
|
||||
|
||||
for j = 0 to 4 do
|
||||
let@ scope =
|
||||
Atomic.incr num_tr;
|
||||
T.Trace.with_ ~kind:T.Span.Span_kind_internal ~scope
|
||||
~attrs:[ "j", `Int j ]
|
||||
"loop.inner"
|
||||
in
|
||||
|
||||
Unix.sleepf !sleep_outer;
|
||||
incr num_sleep;
|
||||
Atomic.incr num_sleep;
|
||||
|
||||
T.Logs.(
|
||||
emit
|
||||
|
|
@ -44,13 +50,16 @@ let run () =
|
|||
incr i;
|
||||
|
||||
try
|
||||
Atomic.incr num_tr;
|
||||
let@ _ = T.Trace.with_ ~kind:T.Span.Span_kind_internal ~scope "alloc" in
|
||||
(* allocate some stuff *)
|
||||
let _arr = Sys.opaque_identity @@ Array.make (25 * 25551) 42.0 in
|
||||
ignore _arr;
|
||||
if !stress_alloc_ then (
|
||||
let _arr = Sys.opaque_identity @@ Array.make (25 * 25551) 42.0 in
|
||||
ignore _arr
|
||||
);
|
||||
|
||||
Unix.sleepf !sleep_inner;
|
||||
incr num_sleep;
|
||||
Atomic.incr num_sleep;
|
||||
|
||||
if j = 4 && !i mod 13 = 0 then failwith "oh no";
|
||||
|
||||
|
|
@ -60,10 +69,32 @@ let run () =
|
|||
done
|
||||
done
|
||||
|
||||
let run () =
|
||||
Printf.printf "collector is on %S\n%!" (Opentelemetry_client_ocurl.get_url ());
|
||||
T.GC_metrics.basic_setup ();
|
||||
|
||||
T.Metrics_callbacks.register (fun () ->
|
||||
T.Metrics.
|
||||
[
|
||||
sum ~name:"num-sleep" ~is_monotonic:true
|
||||
[ int (Atomic.get num_sleep) ];
|
||||
]);
|
||||
|
||||
let n_jobs = max 1 !n_jobs in
|
||||
Printf.printf "run %d jobs\n%!" n_jobs;
|
||||
|
||||
let jobs =
|
||||
Array.init n_jobs (fun _ ->
|
||||
let job () = try run_job () with Sys.Break -> () in
|
||||
Thread.create job ())
|
||||
in
|
||||
Array.iter Thread.join jobs
|
||||
|
||||
let () =
|
||||
Sys.catch_break true;
|
||||
T.Globals.service_name := "t1";
|
||||
T.Globals.service_namespace := Some "ocaml-otel.test";
|
||||
let ts_start = Unix.gettimeofday () in
|
||||
|
||||
let debug = ref false in
|
||||
let thread = ref true in
|
||||
|
|
@ -73,12 +104,16 @@ let () =
|
|||
[
|
||||
"--debug", Arg.Bool (( := ) debug), " enable debug output";
|
||||
"--thread", Arg.Bool (( := ) thread), " use a background thread";
|
||||
( "--stress-alloc",
|
||||
Arg.Bool (( := ) stress_alloc_),
|
||||
" perform heavy allocs in inner loop" );
|
||||
"--batch-traces", Arg.Int (( := ) batch_traces), " size of traces batch";
|
||||
( "--batch-metrics",
|
||||
Arg.Int (( := ) batch_metrics),
|
||||
" size of metrics batch" );
|
||||
"--sleep-inner", Arg.Set_float sleep_inner, " sleep (in s) in inner loop";
|
||||
"--sleep-outer", Arg.Set_float sleep_outer, " sleep (in s) in outer loop";
|
||||
"-j", Arg.Set_int n_jobs, " number of parallel jobs";
|
||||
]
|
||||
|> Arg.align
|
||||
in
|
||||
|
|
@ -100,4 +135,11 @@ let () =
|
|||
Format.printf "@[<2>sleep outer: %.3fs,@ sleep inner: %.3fs,@ config: %a@]@."
|
||||
!sleep_outer !sleep_inner Opentelemetry_client_ocurl.Config.pp config;
|
||||
|
||||
let@ () =
|
||||
Fun.protect ~finally:(fun () ->
|
||||
let elapsed = Unix.gettimeofday () -. ts_start in
|
||||
let n_per_sec = float (Atomic.get num_tr) /. elapsed in
|
||||
Printf.printf "\ndone. %d spans in %.4fs (%.4f/s)\n%!"
|
||||
(Atomic.get num_tr) elapsed n_per_sec)
|
||||
in
|
||||
Opentelemetry_client_ocurl.with_setup ~config () run
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue