Skip to content

Commit 09e4102

Browse files
committed
port allocation funtor to 5.2.1
1 parent 4dbc067 commit 09e4102

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

src/lib/allocation_functor/intf.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open Core_kernel
1+
open Core
22

33
module Partial = struct
44
module type Bin_io_intf = Binable.S

src/lib/allocation_functor/make.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open Core_kernel
1+
open Core
22

33
module Partial = struct
44
module Bin_io (M : Intf.Input.Bin_io_intf) :

src/lib/allocation_functor/table.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
(** immutable, serializable statistics derived from allocation data *)
44
module Allocation_statistics = struct
@@ -33,7 +33,7 @@ module Allocation_data = struct
3333

3434
(* indexed queue data structure would be more effecient here, but keeping this simple for now *)
3535
type t =
36-
{ allocation_times : (allocation_id * Time.t) Queue.t
36+
{ allocation_times : (allocation_id * Time_float.t) Queue.t
3737
; mutable next_allocation_id : allocation_id
3838
}
3939

@@ -44,7 +44,7 @@ module Allocation_data = struct
4444

4545
let register_allocation data =
4646
let id = data.next_allocation_id in
47-
Queue.enqueue data.allocation_times (id, Time.now ()) ;
47+
Queue.enqueue data.allocation_times (id, Time_float.now ()) ;
4848
data.next_allocation_id <- data.next_allocation_id + 1 ;
4949
id
5050

@@ -53,9 +53,11 @@ module Allocation_data = struct
5353
Queue.filter_inplace data.allocation_times ~f:(fun (id', _) -> id = id')
5454

5555
let compute_statistics { allocation_times; _ } =
56-
let now = Time.now () in
56+
let now = Time_float.now () in
5757
let count = Queue.length allocation_times in
58-
let lifetime_ms_of_time time = Time.Span.to_ms (Time.diff now time) in
58+
let lifetime_ms_of_time time =
59+
Time_float.Span.to_ms (Time_float.diff now time)
60+
in
5961
let get_lifetime_ms i =
6062
lifetime_ms_of_time (snd @@ Queue.get allocation_times i)
6163
in
@@ -109,13 +111,13 @@ module Allocation_data = struct
109111

110112
(* time_offsets passed in here should be ordered monotonically (to match real world behavior) *)
111113
let run_test time_offsets expected_quartiles =
112-
let now = Time.now () in
114+
let now = Time_float.now () in
113115
(* ids do not need to be unique in this test *)
114116
let data =
115117
{ allocation_times =
116118
Queue.of_list
117119
@@ List.map (List.rev time_offsets) ~f:(fun offset ->
118-
(0, Time.sub now (Time.Span.of_ms offset)) )
120+
(0, Time_float.sub now (Time_float.Span.of_ms offset)) )
119121
; next_allocation_id = 0
120122
}
121123
in
@@ -164,33 +166,33 @@ let table = String.Table.create ()
164166

165167
let capture object_id =
166168
let open Allocation_info in
167-
let info_opt = String.Table.find table object_id in
169+
let info_opt = Hashtbl.find table object_id in
168170
let data_opt = Option.map info_opt ~f:(fun { data; _ } -> data) in
169171
let data =
170172
Lazy.(
171173
force
172174
@@ Option.value_map data_opt
173175
~default:(lazy (Allocation_data.create ()))
174-
~f:Lazy.return)
176+
~f:Lazy.return )
175177
in
176178
let allocation_id = Allocation_data.register_allocation data in
177179
let statistics = Allocation_data.compute_statistics data in
178-
String.Table.set table ~key:object_id ~data:{ data; statistics } ;
180+
Hashtbl.set table ~key:object_id ~data:{ data; statistics } ;
179181
Allocation_statistics.write_metrics statistics object_id ;
180182
Mina_metrics.(
181-
Counter.inc_one (Object_lifetime_statistics.allocated_count ~name:object_id)) ;
183+
Counter.inc_one (Object_lifetime_statistics.allocated_count ~name:object_id) ) ;
182184
allocation_id
183185

184186
(* release is currently O(n), where n = number of active allocations for this object type; this can be improved by implementing indexed queues (with decent random delete computational complexity) in ocaml *)
185187
let release ~object_id ~allocation_id =
186188
let open Allocation_info in
187-
let info = String.Table.find_exn table object_id in
189+
let info = Hashtbl.find_exn table object_id in
188190
Allocation_data.unregister_allocation info.data allocation_id ;
189191
let statistics = Allocation_data.compute_statistics info.data in
190-
String.Table.set table ~key:object_id ~data:{ info with statistics } ;
192+
Hashtbl.set table ~key:object_id ~data:{ info with statistics } ;
191193
Allocation_statistics.write_metrics statistics object_id ;
192194
Mina_metrics.(
193-
Counter.inc_one (Object_lifetime_statistics.collected_count ~name:object_id))
195+
Counter.inc_one (Object_lifetime_statistics.collected_count ~name:object_id) )
194196

195197
let attach_finalizer object_id obj =
196198
let allocation_id = capture object_id in
@@ -200,8 +202,8 @@ let attach_finalizer object_id obj =
200202
let dump () =
201203
let open Allocation_info in
202204
let entries =
203-
String.Table.to_alist table
205+
Hashtbl.to_alist table
204206
|> List.Assoc.map ~f:(fun { statistics; _ } ->
205-
Allocation_statistics.to_yojson statistics )
207+
Allocation_statistics.to_yojson statistics )
206208
in
207209
`Assoc entries

0 commit comments

Comments
 (0)