This commit is contained in:
Simon Cruanes 2026-02-21 22:37:10 -05:00
parent 210b7991c9
commit 806545f2ba
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 22 additions and 15 deletions

View file

@ -78,7 +78,8 @@ let run env proc iterations () : unit =
sum ~name:"num-sleep" ~is_monotonic:true
[ int ~now (Atomic.get num_sleep) ];
]);
OT.Meter.add_to_main_exporter ~min_interval:Mtime.Span.(10 * ms)
OT.Meter.add_to_main_exporter
~min_interval:Mtime.Span.(10 * ms)
OT.Meter.default;
let n_jobs = max 1 !n_jobs in

View file

@ -5,8 +5,7 @@ let dummy_clock : Clock.t = { Clock.now = (fun () -> 0L) }
let emit h = h.Instrument.emit ~clock:dummy_clock ()
let pp_metrics metrics =
List.iter (Format.printf "%a@." Metrics.pp) metrics
let pp_metrics metrics = List.iter (Format.printf "%a@." Metrics.pp) metrics
(* ------------------------------------------------------------------ *)
(* Test 1: one value per bucket, plus one in the overflow bucket *)
@ -16,23 +15,27 @@ let () =
Instrument.Histogram.create ~name:"test.latency"
~description:"test histogram" ~bounds:[ 1.; 2.; 5. ] ()
in
Instrument.Histogram.record h 0.5; (* bucket 0: ≤1 *)
Instrument.Histogram.record h 1.5; (* bucket 1: ≤2 *)
Instrument.Histogram.record h 3.0; (* bucket 2: ≤5 *)
Instrument.Histogram.record h 10.; (* bucket 3: >5 *)
Instrument.Histogram.record h 0.5;
(* bucket 0: ≤1 *)
Instrument.Histogram.record h 1.5;
(* bucket 1: ≤2 *)
Instrument.Histogram.record h 3.0;
(* bucket 2: ≤5 *)
Instrument.Histogram.record h 10.;
(* bucket 3: >5 *)
(* count=4 sum=15.0 bucket_counts=[1;1;1;1] *)
pp_metrics (emit h)
(* ------------------------------------------------------------------ *)
(* Test 2: multiple values pile into the same bucket *)
let () =
let h =
Instrument.Histogram.create ~name:"test.size" ~bounds:[ 1.; 5. ] ()
in
let h = Instrument.Histogram.create ~name:"test.size" ~bounds:[ 1.; 5. ] () in
Instrument.Histogram.record h 0.1;
Instrument.Histogram.record h 0.2;
Instrument.Histogram.record h 0.3; (* 3 values in bucket 0 *)
Instrument.Histogram.record h 2.0; (* 1 value in bucket 1 *)
Instrument.Histogram.record h 0.3;
(* 3 values in bucket 0 *)
Instrument.Histogram.record h 2.0;
(* 1 value in bucket 1 *)
(* count=4 sum=2.6 bucket_counts=[3;1;0] *)
pp_metrics (emit h)
@ -51,8 +54,11 @@ let () =
let h =
Instrument.Histogram.create ~name:"test.boundary" ~bounds:[ 1.; 2.; 5. ] ()
in
Instrument.Histogram.record h 1.0; (* exactly on bound → bucket 0 *)
Instrument.Histogram.record h 2.0; (* exactly on bound → bucket 1 *)
Instrument.Histogram.record h 5.0; (* exactly on bound → bucket 2 *)
Instrument.Histogram.record h 1.0;
(* exactly on bound → bucket 0 *)
Instrument.Histogram.record h 2.0;
(* exactly on bound → bucket 1 *)
Instrument.Histogram.record h 5.0;
(* exactly on bound → bucket 2 *)
(* count=3 sum=8.0 bucket_counts=[1;1;1;0] *)
pp_metrics (emit h)