Skip to content

Commit

Permalink
Merge pull request #51 from hannesm/next
Browse files Browse the repository at this point in the history
Add Xen_os.Memory.metrics, a metrics source.
  • Loading branch information
hannesm authored Mar 3, 2023
2 parents 560834a + 087ea9f commit d1ee224
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 0.21.0
version = 0.24.1
profile = conventional

parse-docstrings = true
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v8.0.2 (2023-03-03)

* Provide Memory.metrics, a metrics source. Remove Mm.metrics metrics source.
(#51 @hannesm)

## v8.0.1 (2022-10-19)

* Improve performance and take the opportunity to resolve pending
Expand Down
3 changes: 2 additions & 1 deletion lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
(name xen_os)
(public_name mirage-xen)
(libraries lwt cstruct xenstore.client shared-memory-ring-lwt lwt-dllist
mirage-profile logs io-page fmt mirage-runtime bheap duration)
mirage-profile logs io-page fmt mirage-runtime bheap duration metrics
metrics-lwt)
(no_dynlink)
(foreign_archives mirage-xen_bindings))

Expand Down
18 changes: 18 additions & 0 deletions lib/memory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,21 @@ let quick_stat () =
let l = get_fast_live_words () in
let s = get_stack_words () in
{ heap_words = h; live_words = l; stack_words = s; free_words = h - l - s }

let metrics ?(quick = true) ~tags () =
let open Metrics in
let doc = "Memory counters" in
let stat = if quick then quick_stat else stat in
let data () =
let stat = stat () in
Data.v
[
uint "memory heap words" stat.heap_words;
uint "memory live words" stat.live_words;
uint "memory stack words" stat.stack_words;
uint "memory free words" stat.free_words;
]
in
Src.v ~doc ~tags ~data "memory"

let () = Metrics_lwt.periodically (metrics ~tags:Metrics.Tags.[] ())
9 changes: 9 additions & 0 deletions lib/xen_os.mli
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ module Memory : sig
val trim : unit -> unit
(** [trim ()] release free memory from the heap (may update the value returned
by {!quick_stat}) *)

val metrics :
?quick:bool ->
tags:'a Metrics.Tags.t ->
unit ->
('a, unit -> Metrics.Data.t) Metrics.src
(** [metrics ~quick ~tags] is a metrics source calling {quick_stat} (unless
[quick] is set to [false]) or {stat}. By default, this metrics source is
registered with [Metrics_lwt.periodically] (with [quick] set to [true]. *)
end

module Time : sig
Expand Down
2 changes: 2 additions & 0 deletions mirage-xen.opam
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ depends: [
"fmt" {>= "0.8.5"}
"bheap" {>= "2.0.0"}
"duration"
"metrics"
"metrics-lwt" {>= "0.2.0"}
]
available: [
(arch = "x86_64" ) &
Expand Down

0 comments on commit d1ee224

Please sign in to comment.