@ -13,14 +13,17 @@ type table = InferEvents
type sample =
type sample =
{ int_section : int SMap . t (* * All integer type fields and their values *)
{ int_section : int SMap . t (* * All integer type fields and their values *)
; normal_section : string SMap . t
; normal_section : string SMap . t
(* * All string ( normal in Scuba terminology ) type fields and their values *) }
(* * All string ( normal in Scuba terminology ) type fields and their values *)
; tagset_section : string list SMap . t
(* * All sets of strings ( tagsets in Scuba terminology ) type fields and their values *) }
let new_sample ~ time =
let new_sample ~ time =
let time = match time with Some time -> time | None -> int_of_float ( Unix . time () ) in
let time = match time with Some time -> time | None -> int_of_float ( Unix . time () ) in
{ (* time is a single mandatory field in scuba. without it,
{ (* time is a single mandatory field in scuba. without it,
scuba disregards all samples * )
scuba disregards all samples * )
int_section = SMap . singleton " time " time
int_section = SMap . singleton " time " time
; normal_section = SMap . empty }
; normal_section = SMap . empty
; tagset_section = SMap . empty }
let add_int ~ name ~ value sample =
let add_int ~ name ~ value sample =
@ -33,6 +36,11 @@ let add_normal ~name ~value sample =
{ sample with normal_section }
{ sample with normal_section }
let add_tagset ~ name ~ value sample =
let tagset_section = SMap . set sample . tagset_section ~ key : name ~ data : value in
{ sample with tagset_section }
let sample_to_json sample =
let sample_to_json sample =
let map_to_assoc value_to_json key_value_map =
let map_to_assoc value_to_json key_value_map =
let pairs = SMap . to_alist key_value_map in
let pairs = SMap . to_alist key_value_map in
@ -41,8 +49,11 @@ let sample_to_json sample =
in
in
let ints_to_assoc = map_to_assoc ( fun data -> ` Int data ) in
let ints_to_assoc = map_to_assoc ( fun data -> ` Int data ) in
let normals_to_assoc = map_to_assoc ( fun data -> ` String data ) in
let normals_to_assoc = map_to_assoc ( fun data -> ` String data ) in
let tags_to_assoc = map_to_assoc ( fun data -> ` List ( List . map data ~ f : ( fun d -> ` String d ) ) ) in
` Assoc
` Assoc
[ ( " int " , ints_to_assoc sample . int_section ) ; ( " normal " , normals_to_assoc sample . normal_section ) ]
[ ( " int " , ints_to_assoc sample . int_section )
; ( " normal " , normals_to_assoc sample . normal_section )
; ( " tags " , tags_to_assoc sample . tagset_section ) ]
let sample_to_json_string sample = sample | > sample_to_json | > Yojson . Basic . to_string
let sample_to_json_string sample = sample | > sample_to_json | > Yojson . Basic . to_string