mirror of
https://github.com/ocaml-tracing/ocaml-trace.git
synced 2026-03-08 03:47:57 -04:00
Add basic landmarks data types with yojson encoders
This commit is contained in:
parent
6517ee32bc
commit
a9054e48f3
2 changed files with 68 additions and 16 deletions
|
|
@ -8,12 +8,12 @@ type gc_info = {
|
|||
(** Basic GC statistics *)
|
||||
|
||||
(** Convert gc_info to yojson *)
|
||||
let gc_info_to_yojson (gc : gc_info) : Yojson.Safe.t =
|
||||
let gc_info_to_yojson (self : gc_info) : Yojson.Safe.t =
|
||||
`Assoc
|
||||
[
|
||||
"minor_words", `Float gc.minor_words;
|
||||
"promoted_words", `Float gc.promoted_words;
|
||||
"major_words", `Float gc.major_words;
|
||||
"minor_words", `Float self.minor_words;
|
||||
"promoted_words", `Float self.promoted_words;
|
||||
"major_words", `Float self.major_words;
|
||||
]
|
||||
|
||||
type timing = {
|
||||
|
|
@ -25,13 +25,13 @@ type timing = {
|
|||
(** Timing information *)
|
||||
|
||||
(** Convert timing to yojson *)
|
||||
let timing_to_yojson (t : timing) : Yojson.Safe.t =
|
||||
let timing_to_yojson (self : timing) : Yojson.Safe.t =
|
||||
`Assoc
|
||||
[
|
||||
"start_time", `Float t.start_time;
|
||||
"end_time", `Float t.end_time;
|
||||
"duration", `Float t.duration;
|
||||
"cpu_time", `Float t.cpu_time;
|
||||
"start_time", `Float self.start_time;
|
||||
"end_time", `Float self.end_time;
|
||||
"duration", `Float self.duration;
|
||||
"cpu_time", `Float self.cpu_time;
|
||||
]
|
||||
|
||||
type landmark = {
|
||||
|
|
@ -45,17 +45,17 @@ type landmark = {
|
|||
(** A single landmark measurement *)
|
||||
|
||||
(** Convert landmark to yojson *)
|
||||
let landmark_to_yojson (lm : landmark) : Yojson.Safe.t =
|
||||
let landmark_to_yojson (self : landmark) : Yojson.Safe.t =
|
||||
`Assoc
|
||||
([
|
||||
"name", `String lm.name;
|
||||
"timing", timing_to_yojson lm.timing;
|
||||
"gc_before", gc_info_to_yojson lm.gc_before;
|
||||
"gc_after", gc_info_to_yojson lm.gc_after;
|
||||
"call_count", `Int lm.call_count;
|
||||
"name", `String self.name;
|
||||
"timing", timing_to_yojson self.timing;
|
||||
"gc_before", gc_info_to_yojson self.gc_before;
|
||||
"gc_after", gc_info_to_yojson self.gc_after;
|
||||
"call_count", `Int self.call_count;
|
||||
]
|
||||
@
|
||||
match lm.location with
|
||||
match self.location with
|
||||
| None -> []
|
||||
| Some loc -> [ "location", `String loc ])
|
||||
|
||||
|
|
|
|||
52
src/landmarks/data.mli
Normal file
52
src/landmarks/data.mli
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
(** Basic data types for Landmarks profiling export *)
|
||||
|
||||
(** GC statistics at a point in time *)
|
||||
type gc_info = {
|
||||
minor_words : float;
|
||||
promoted_words : float;
|
||||
major_words : float;
|
||||
minor_collections : int;
|
||||
major_collections : int;
|
||||
heap_words : int;
|
||||
compactions : int;
|
||||
}
|
||||
|
||||
val gc_info_to_yojson : gc_info -> Yojson.Safe.t
|
||||
(** Convert gc_info to yojson *)
|
||||
|
||||
(** Timing information *)
|
||||
type timing = {
|
||||
start_time : float; (** Start timestamp (seconds) *)
|
||||
end_time : float; (** End timestamp (seconds) *)
|
||||
duration : float; (** Duration in seconds *)
|
||||
cpu_time : float; (** CPU time in seconds *)
|
||||
}
|
||||
|
||||
val timing_to_yojson : timing -> Yojson.Safe.t
|
||||
(** Convert timing to yojson *)
|
||||
|
||||
(** A single landmark measurement *)
|
||||
type landmark = {
|
||||
name : string;
|
||||
location : string option;
|
||||
timing : timing;
|
||||
gc_before : gc_info;
|
||||
gc_after : gc_info;
|
||||
call_count : int;
|
||||
}
|
||||
|
||||
val landmark_to_yojson : landmark -> Yojson.Safe.t
|
||||
(** Convert landmark to yojson *)
|
||||
|
||||
(** A collection of landmarks *)
|
||||
type landmark_collection = {
|
||||
landmarks : landmark list;
|
||||
total_time : float;
|
||||
timestamp : float;
|
||||
}
|
||||
|
||||
val landmark_collection_to_yojson : landmark_collection -> Yojson.Safe.t
|
||||
(** Convert landmark_collection to yojson *)
|
||||
|
||||
val get_gc_info : unit -> gc_info
|
||||
(** Helper to get current GC info from Gc.stat *)
|
||||
Loading…
Add table
Reference in a new issue