@@ -42,8 +42,8 @@ module Compat = struct
4242 let mtime_clock_count = Mtime_clock. count
4343 let mtime_span_to_s = Mtime.Span. to_s
4444 let file_lines_fold = Xapi_stdext_unix.Unixext. file_lines_fold
45- let mutex_execute = Xapi_stdext_Threads .Threadext.Mutex. execute
46- let reporter_async ~shared_page_count ~dssf =
45+ let mutex_execute = Xapi_stdext_threads .Threadext.Mutex. execute
46+ let reporter_async ~shared_page_count ~dss_f =
4747 let reporter = Reporter. make () in
4848 let (th : Thread.t ) =
4949 Thread. create
@@ -52,29 +52,23 @@ module Compat = struct
5252 (module D : Debug.DEBUG )
5353 ~reporter: (Some reporter) ~uid: " xenopsd-stats"
5454 ~neg_shift: 0.5 ~page_count: shared_page_count
55- ~protocol: Rrd_interface. V2 ~dss_f: generate_stats
55+ ~protocol: Rrd_interface. V2 ~dss_f
5656 )
5757 ()
5858 in
59- (th, reporter)
59+ (th, reporter)
6060 let reporter_cancel (th , reporter ) =
61- Reporter. cancel reporter;
62- Thread. join th
61+ Reporter. cancel reporter;
62+ Thread. join th
6363 let reporter_cache : (Thread.t * Reporter.t) option ref = ref None
6464
6565end
6666open Compat
6767
6868module SlowReporter = struct
69- let ds_to_unknown = function
70- | Rrd. VT_Int64 _ -> Rrd. VT_Int64 (- 1L )
71- | Rrd. VT_Float _ | Rrd. VT_Unknown -> Rrd. VT_Float nan
72-
73- let to_unknown dss =
74- dss |> List. rev_map (fun ds -> { ds with Ds. ds_value = ds_to_unknown ds.Ds. ds_value } ) |> List. rev
75-
7669 (* * [report ~interval_s ~generate_dss] calls [generate_dss] every [interval_s] only,
77- and substitutes VT_Unknown when called more often.
70+ and substitutes the previous value when called more often.
71+ Using VT_Unknown or NaN would leave gaps in the graph.
7872 Report_local only supports reporting at 5s intervals, but some metrics are too costly to
7973 gather that often, e.g. Gc.stat needs to walk the entire heap.
8074 *)
@@ -197,24 +191,30 @@ module Proc = struct
197191 let vmdata = " VmData"
198192 let vmpte = " VmPTE"
199193 let threads = " Threads"
194+ let fdsize = " FDSize"
195+ let vmsize = " VmSize"
196+ let vmlck = " VmLck"
197+ let vmpin = " VmPin"
198+ let vmstk = " VmStk"
199+ let rss = " Rss"
200200
201201 (* there is also /proc/self/stat and /proc/self/statm, but we'd need to open and parse both *)
202202 let status = define_fields ~path: " status"
203203 [ count threads " Total number of threads used by %s"
204- ; count " FDSize " " Total number of file descriptors used by %s"
205- ; kib " VmSize " " Total amount of memory mapped by %s"
206- ; kib " VmLck " " Total amount of memory locked by %s"
207- ; kib " VmPin " " Total amount of memory pinned by %s"
204+ ; count fdsize " Total number of file descriptors used by %s"
205+ ; kib vmsize " Total amount of memory mapped by %s"
206+ ; kib vmlck " Total amount of memory locked by %s"
207+ ; kib vmpin " Total amount of memory pinned by %s"
208208 (* VmRSS is inaccurate accoring to latest proc(5) *)
209209 ; kib vmdata " Total amount of writable, non-shared and non-stack memory used by %s"
210- ; kib " VmStk " " Total amount of main stack memory used by %s"
210+ ; kib vmstk " Total amount of main stack memory used by %s"
211211 ; kib vmpte " Total amount of page table entry memory used by %s"
212212 ]
213213
214214 (* According to latest proc(5) these are slower, but provide more accurate information.
215215 The RSS reported by other stat counters could be off depending on the number of threads. *)
216216 let smaps_rollup = define_fields ~path: " smaps_rollup" [
217- kib " Rss " " Total amount of resident memory used by %s"
217+ kib rss " Total amount of resident memory used by %s"
218218 ]
219219 end
220220
@@ -230,23 +230,23 @@ module GcStat = struct
230230 open Gc
231231
232232 let ocaml_total =
233- let f = kib " ocaml_total" " Total OCaml memory used by %s" in
233+ let field = kib " ocaml_total" " Total OCaml memory used by %s" in
234234 fun gc control ->
235235 gc.heap_words + control.minor_heap_size
236- |> float |> words_to_kib |> f
236+ |> float |> words_to_kib |> field
237237
238238 let maybe_words name description v =
239239 (* quick_stat would return a value of 0, which is not valid *)
240240 v |> float |> words_to_kib |> kib ~min: 0.001 name description
241241
242- let compute (gc , control ) =
242+ let memory_allocation_precise (gc , control ) =
243243 [ ocaml_total gc control
244244 ; gc.minor_words +. gc.major_words -. gc.promoted_words
245245 |> words_to_kib
246246 |> kib_per_s " ocaml_allocation_rate" " Amount of allocations done by OCaml in the given period by %s"
247247 ]
248248
249- let compute_slow (gc , control ) =
249+ let memory_allocation_approx_expensive (gc , control ) =
250250 [
251251 (* see https://github.com/ocaml/ocaml/blob/trunk/stdlib/gc.mli#L50-L59, without running a major
252252 cycle the live_words may overestimate the actual live words, "live" just means "not currently
@@ -289,12 +289,12 @@ let observe_stats l =
289289 D. debug " stats header: %s" (String. concat " ," names);
290290 D. debug " stats values: %s" (String. concat " ," values)
291291
292- let generate_slow_stats =
292+ let generate_expensive_stats =
293293 let generate_dss () =
294294 let stat = Gc. stat () in
295295 let gc_control = Gc. get () in
296296 let rss = Proc.Fields. smaps_rollup () |> Proc. to_list in
297- let gcstat = GcStat. compute_slow (stat, gc_control) in
297+ let gcstat = GcStat. memory_allocation_approx_expensive (stat, gc_control) in
298298 List. rev_append rss gcstat
299299 in
300300 SlowReporter. iter_of_fold (SlowReporter. report ~interval_s: 150. ~generate_dss )
@@ -304,8 +304,8 @@ let generate_stats () =
304304 let gc_stat = Gc. quick_stat () in
305305 let gc_control = Gc. get () in
306306 let derived = Derived. memextra_kib status (gc_stat, gc_control) in
307- let gcstat = GcStat. compute (gc_stat, gc_control) in
308- let is_slow, slow_stats = generate_slow_stats () in
307+ let gcstat = GcStat. memory_allocation_precise (gc_stat, gc_control) in
308+ let is_slow, slow_stats = generate_expensive_stats () in
309309 let stats = derived :: List. concat [
310310 gcstat;
311311 Proc. to_list status;
0 commit comments