Skip to content

Commit 4dbc067

Browse files
committed
port perf_histograms to 5.2.1
1 parent b064420 commit 4dbc067

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed

src/lib/perf_histograms/histogram.ml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open Core_kernel
1+
open Core
22

33
(** Loosely modelled on https://chromium.googlesource.com/chromium/src/+/HEAD/tools/metrics/histograms/README.md *)
44

@@ -71,15 +71,15 @@ end
7171

7272
module Exp_time_spans = Make (struct
7373
(** Note: All time spans are represented in JSON as floating point millis *)
74-
type t = Time.Span.t [@@deriving bin_io_unversioned]
74+
type t = Time_float.Span.t [@@deriving bin_io_unversioned]
7575

76-
let to_yojson t = `Float (Time.Span.to_ms t)
76+
let to_yojson t = `Float (Time_float.Span.to_ms t)
7777

7878
let of_yojson t =
7979
let open Ppx_deriving_yojson_runtime in
8080
match t with
8181
| `Float ms ->
82-
Result.Ok (Time.Span.of_ms ms)
82+
Result.Ok (Time_float.Span.of_ms ms)
8383
| _ ->
8484
Result.Error "Not a floating point milliseconds value"
8585

@@ -92,8 +92,8 @@ module Exp_time_spans = Make (struct
9292

9393
(* See http://mathworld.wolfram.com/LeastSquaresFittingLogarithmic.html *)
9494
let fit min max buckets =
95-
let x0, y0 = (Time.Span.to_ms min, Float.zero) in
96-
let x1, y1 = (Time.Span.to_ms max, Float.of_int buckets) in
95+
let x0, y0 = (Time_float.Span.to_ms min, Float.zero) in
96+
let x1, y1 = (Time_float.Span.to_ms max, Float.of_int buckets) in
9797
let n = 2.0 in
9898
let sum f = f (x0, y0) +. f (x1, y1) in
9999
let b =
@@ -126,8 +126,8 @@ module Exp_time_spans = Make (struct
126126
in
127127
(a, b)
128128

129-
let create ?(min = Time.Span.of_sec 1.) ?(max = Time.Span.of_min 10.)
130-
?(buckets = 50) () =
129+
let create ?(min = Time_float.Span.of_sec 1.)
130+
?(max = Time_float.Span.of_min 10.) ?(buckets = 50) () =
131131
let a, b = fit min max buckets in
132132
{ a; b; buckets }
133133
end
@@ -138,10 +138,10 @@ module Exp_time_spans = Make (struct
138138
let y = Float.of_int y in
139139
Float.exp ((y /. b) -. (a /. b))
140140
in
141-
(Time.Span.of_ms (f_1 i), Time.Span.of_ms (f_1 (i + 1)))
141+
(Time_float.Span.of_ms (f_1 i), Time_float.Span.of_ms (f_1 (i + 1)))
142142

143143
let bucket ~params:{ Params.a; b; buckets } span =
144-
let x = Time.Span.to_ms span in
144+
let x = Time_float.Span.to_ms span in
145145
if Float.( <= ) x 0.0 then `Underflow
146146
else
147147
(* y = a + b log(x) *)
@@ -154,19 +154,21 @@ end)
154154
let%test_unit "reports properly with overflows and underflows and table hits" =
155155
let open Exp_time_spans in
156156
let tbl =
157-
create ~buckets:50 ~min:(Time.Span.of_ms 1.) ~max:(Time.Span.of_day 1.) ()
157+
create ~buckets:50 ~min:(Time_float.Span.of_ms 1.)
158+
~max:(Time_float.Span.of_day 1.)
159+
()
158160
in
159161
let r = report tbl in
160162
assert (r.Pretty.underflow = 0) ;
161163
assert (r.Pretty.overflow = 0) ;
162164
(* underflow *)
163-
add tbl (Time.Span.of_us 100.) ;
165+
add tbl (Time_float.Span.of_us 100.) ;
164166
(* in the table *)
165-
add tbl (Time.Span.of_ms 100.) ;
166-
add tbl (Time.Span.of_sec 100.) ;
167-
add tbl (Time.Span.of_day 0.5) ;
167+
add tbl (Time_float.Span.of_ms 100.) ;
168+
add tbl (Time_float.Span.of_sec 100.) ;
169+
add tbl (Time_float.Span.of_day 0.5) ;
168170
(* overflow *)
169-
add tbl (Time.Span.of_day 2.) ;
171+
add tbl (Time_float.Span.of_day 2.) ;
170172
let r = report tbl in
171173
assert (List.sum ~f:Fn.id (module Int) r.Pretty.values = 3) ;
172174
assert (r.Pretty.underflow = 1) ;

src/lib/perf_histograms/perf_histograms.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open Core_kernel
1+
open Core
22

33
module Rpc : sig
44
module Plain : sig
@@ -18,14 +18,14 @@ end
1818
module Report : sig
1919
type t =
2020
{ values : int list
21-
; intervals : (Time.Span.t * Time.Span.t) list
21+
; intervals : (Time_float.Span.t * Time_float.Span.t) list
2222
; underflow : int
2323
; overflow : int
2424
}
2525
[@@deriving yojson, bin_io, fields]
2626
end
2727

28-
val add_span : name:string -> Time.Span.t -> unit
28+
val add_span : name:string -> Time_float.Span.t -> unit
2929

3030
val report : name:string -> Report.t option
3131

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
open Core_kernel
1+
open Core
22

33
(* For now, we'll just support Exp_time_spans histogram *)
44
let t : Histogram.Exp_time_spans.t String.Table.t = String.Table.create ()
55

66
let add_span ~name s =
77
let hist =
8-
String.Table.find_or_add t name ~default:Histogram.Exp_time_spans.create
8+
Hashtbl.find_or_add t name ~default:Histogram.Exp_time_spans.create
99
in
1010
Histogram.Exp_time_spans.add hist s
1111

1212
let report ~name =
13-
String.Table.find_and_call t name
13+
Hashtbl.find_and_call t name
1414
~if_found:(fun tbl -> Some (Histogram.Exp_time_spans.report tbl))
1515
~if_not_found:(fun _ -> None)
1616

17-
let wipe () =
18-
String.Table.iter t ~f:(fun tbl -> Histogram.Exp_time_spans.clear tbl)
17+
let wipe () = Hashtbl.iter t ~f:(fun tbl -> Histogram.Exp_time_spans.clear tbl)

src/lib/perf_histograms/rpc.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@ let decorate_dispatch ~name (dispatch : ('q, 'r) Intf.dispatch) :
55
('q, 'r) Intf.dispatch =
66
fun conn q ->
77
let open Deferred.Or_error.Let_syntax in
8-
let start = Time.now () in
8+
let start = Time_float.now () in
99
let%map r = dispatch conn q in
10-
let span = Time.diff (Time.now ()) start in
10+
let span = Time_float.diff (Time_float.now ()) start in
1111
Perf_histograms0.add_span ~name:(sprintf "rpc_dispatch_%s" name) span ;
1212
Mina_metrics.(
1313
Network.Rpc_latency_histogram.observe Network.rpc_latency_ms_summary
14-
(Time.Span.to_ms span)) ;
15-
Mina_metrics.(Gauge.set (Network.rpc_latency_ms ~name) (Time.Span.to_ms span)) ;
14+
(Time_float.Span.to_ms span) ) ;
15+
Mina_metrics.(
16+
Gauge.set (Network.rpc_latency_ms ~name) (Time_float.Span.to_ms span) ) ;
1617
r
1718

1819
let decorate_impl ~name (impl : ('q, 'r, 'state) Intf.impl) :
1920
('q, 'r, 'state) Intf.impl =
2021
fun state ~version q ->
2122
let open Deferred.Let_syntax in
22-
let start = Time.now () in
23+
let start = Time_float.now () in
2324
let%map r = impl state ~version q in
2425
Perf_histograms0.add_span
2526
~name:(sprintf "rpc_impl_%s" name)
26-
(Time.diff (Time.now ()) start) ;
27+
(Time_float.diff (Time_float.now ()) start) ;
2728
r
2829

2930
module Plain = struct

0 commit comments

Comments
 (0)