···73737474 let bench = foreign "icepick_bench"
7575 (ptr void @-> size_t @-> size_t @-> ptr Latency_stats.t @-> returning int)
7676+7777+ module Monitor = struct
7878+ type t = unit ptr
7979+ let t : t typ = ptr void
8080+8181+ let start = foreign "icepick_monitor_start" (Region.t @-> ptr t @-> returning int)
8282+ let start_ex = foreign "icepick_monitor_start_ex"
8383+ (Region.t @-> uint64_t @-> uint64_t @-> uint32_t @-> ptr t @-> returning int)
8484+ let stop = foreign "icepick_monitor_stop" (t @-> returning int)
8585+ let eviction_count = foreign "icepick_monitor_eviction_count" (t @-> returning uint64_t)
8686+ let reprime_count = foreign "icepick_monitor_reprime_count" (t @-> returning uint64_t)
8787+ let is_degraded = foreign "icepick_monitor_is_degraded" (t @-> returning bool)
8888+ end
7689end
77907891module Topology = struct
···171184 let typed_ptr = from_voidp double (to_voidp region_ptr) in
172185 CArray.from_ptr typed_ptr len |> CArray.to_list |> Array.of_list |>
173186 Bigarray.Array1.of_array Bigarray.Float64 Bigarray.c_layout
187187+end
188188+189189+module Monitor = struct
190190+ type t = {
191191+ ptr : C.Monitor.t;
192192+ region : Region.t;
193193+ mutable stopped : bool;
194194+ }
195195+196196+ let release t =
197197+ if not t.stopped then begin
198198+ let _ = C.Monitor.stop t.ptr in
199199+ t.stopped <- true
200200+ end
201201+202202+ let start region =
203203+ let ptr_ref = allocate C.Monitor.t (from_voidp void null) in
204204+ let ret = C.Monitor.start region.Region.ptr ptr_ref in
205205+ C.check_error ret;
206206+ let t = { ptr = !@ ptr_ref; region; stopped = false } in
207207+ Gc.finalise release t;
208208+ t
209209+210210+ let start_ex region ~pmu_poll_ns ~probe_ns ~miss_thresh =
211211+ let ptr_ref = allocate C.Monitor.t (from_voidp void null) in
212212+ let ret = C.Monitor.start_ex region.Region.ptr
213213+ (Unsigned.UInt64.of_int pmu_poll_ns)
214214+ (Unsigned.UInt64.of_int probe_ns)
215215+ (Unsigned.UInt32.of_int miss_thresh)
216216+ ptr_ref in
217217+ C.check_error ret;
218218+ let t = { ptr = !@ ptr_ref; region; stopped = false } in
219219+ Gc.finalise release t;
220220+ t
221221+222222+ let stop t =
223223+ if not t.stopped then begin
224224+ let ret = C.Monitor.stop t.ptr in
225225+ t.stopped <- true;
226226+ C.check_error ret
227227+ end
228228+229229+ let eviction_count t = Unsigned.UInt64.to_int (C.Monitor.eviction_count t.ptr)
230230+ let reprime_count t = Unsigned.UInt64.to_int (C.Monitor.reprime_count t.ptr)
231231+ let is_degraded t = C.Monitor.is_degraded t.ptr
174232end
175233176234let verify region =
···3535 }
3636end
37373838+module Monitor : sig
3939+ type t
4040+4141+ val start : Region.t -> t
4242+ val start_ex : Region.t -> pmu_poll_ns:int -> probe_ns:int -> miss_thresh:int -> t
4343+ val stop : t -> unit
4444+ val eviction_count : t -> int
4545+ val reprime_count : t -> int
4646+ val is_degraded : t -> bool
4747+end
4848+3849val verify : Region.t -> Latency_stats.t
3950val bench : nativeint -> size:int -> iterations:int -> Latency_stats.t