mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 03:05:31 -05:00
feat(profile): add basic counters
This commit is contained in:
parent
27ccd367b2
commit
1b0d47a01d
3 changed files with 27 additions and 0 deletions
|
|
@ -59,6 +59,21 @@ module Make () : P.BACKEND = struct
|
|||
pid tid ts name;
|
||||
()
|
||||
|
||||
let emit_count_event ~name ~ts (cs : _ list) : unit =
|
||||
let pid = Unix.getpid () in
|
||||
let tid = Thread.id (Thread.self ()) in
|
||||
emit_sep_ ();
|
||||
Printf.fprintf oc
|
||||
{json|{"pid": %d,"cat":"","tid": %d,"ts": %.2f,"name":"%s","ph":"C","args":{|json}
|
||||
pid tid ts name;
|
||||
List.iteri
|
||||
(fun i (n, value) ->
|
||||
if i > 0 then Printf.fprintf oc ",";
|
||||
Printf.fprintf oc {json|"%s":%d|json} n value)
|
||||
cs;
|
||||
Printf.fprintf oc {json|}}|json};
|
||||
()
|
||||
|
||||
let teardown () = teardown_ oc
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ module type BACKEND = sig
|
|||
name:string -> start:float -> end_:float -> unit -> unit
|
||||
|
||||
val emit_instant_event : name:string -> ts:float -> unit -> unit
|
||||
val emit_count_event : name:string -> ts:float -> (string * int) list -> unit
|
||||
val teardown : unit -> unit
|
||||
end
|
||||
|
||||
|
|
@ -36,6 +37,15 @@ let[@inline] instant name =
|
|||
let now = B.get_ts () in
|
||||
B.emit_instant_event ~name ~ts:now ()
|
||||
|
||||
let[@inline] count name cs =
|
||||
if cs <> [] then (
|
||||
match !out_ with
|
||||
| None -> ()
|
||||
| Some (module B) ->
|
||||
let now = B.get_ts () in
|
||||
B.emit_count_event ~name ~ts:now cs
|
||||
)
|
||||
|
||||
(* slow path *)
|
||||
let[@inline never] exit_full_ (module B : BACKEND) name start =
|
||||
let now = B.get_ts () in
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ val exit : probe -> unit
|
|||
val with_ : string -> (unit -> 'a) -> 'a
|
||||
val with1 : string -> ('a -> 'b) -> 'a -> 'b
|
||||
val with2 : string -> ('a -> 'b -> 'c) -> 'a -> 'b -> 'c
|
||||
val count : string -> (string * int) list -> unit
|
||||
|
||||
module type BACKEND = sig
|
||||
val get_ts : unit -> float
|
||||
|
|
@ -22,6 +23,7 @@ module type BACKEND = sig
|
|||
name:string -> start:float -> end_:float -> unit -> unit
|
||||
|
||||
val emit_instant_event : name:string -> ts:float -> unit -> unit
|
||||
val emit_count_event : name:string -> ts:float -> (string * int) list -> unit
|
||||
val teardown : unit -> unit
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue