File: metric.ml

package info (click to toggle)
ocaml-multicore-bench 0.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 320 kB
  • sloc: ml: 1,476; sh: 60; makefile: 6
file content (23 lines) | stat: -rw-r--r-- 744 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
type t = Yojson.Safe.t

let a_non_breaking_space = " "

let to_nonbreaking s =
  s |> String.split_on_char ' ' |> String.concat a_non_breaking_space

let name ~metric ~config = to_nonbreaking (metric ^ "/" ^ config)

let make ~metric ~config ?units ?trend ?description
    (value : [< `Float of float ]) =
  let[@inline] ( @: ) x_opt xs =
    match x_opt with None -> xs | Some x -> x :: xs
  in
  `Assoc
    (Some ("name", `String (name ~metric ~config))
    @: Some ("value", (value :> t))
    @: Option.map (fun units -> ("units", `String units)) units
    @: Option.map (fun trend -> ("trend", Trend.to_json trend)) trend
    @: Option.map
         (fun description -> ("description", `String description))
         description
    @: [])