Skip to content
Snippets Groups Projects
Commit 532ce243 authored by Andre Maroneze's avatar Andre Maroneze Committed by David Bühler
Browse files

[Eva] add datatype for flamegraph data

parent a131c462
No related branches found
No related tags found
No related merge requests found
...@@ -364,6 +364,16 @@ let stack_flamegraph = ref [] ...@@ -364,6 +364,16 @@ let stack_flamegraph = ref []
callee, or when the analysis of the function ends. This stack is never callee, or when the analysis of the function ends. This stack is never
empty when an analysis is in progress. *) empty when an analysis is in progress. *)
module EvaFlamegraph =
State_builder.Hashtbl
(Callstack.Hashtbl)
(Datatype.Float)
(struct
let name = "Eva.Flamegraph"
let dependencies = [ Ast.self ]
let size = 20
end)
(* pretty-prints the functions in a Value callstack, starting by main (i.e. (* pretty-prints the functions in a Value callstack, starting by main (i.e.
in reverse order). *) in reverse order). *)
let pretty_callstack oc callstack = let pretty_callstack oc callstack =
...@@ -392,6 +402,7 @@ let start_doing_flamegraph callstack = ...@@ -392,6 +402,7 @@ let start_doing_flamegraph callstack =
let file = Parameters.ValPerfFlamegraphs.get () in let file = Parameters.ValPerfFlamegraphs.get () in
try try
(* Flamegraphs must be computed. Set up the stack and the output file *) (* Flamegraphs must be computed. Set up the stack and the output file *)
EvaFlamegraph.clear ();
let oc = open_out (file:>string) in let oc = open_out (file:>string) in
oc_flamegraph := Some oc; oc_flamegraph := Some oc;
stack_flamegraph := [ (Sys.time (), 0.) ] stack_flamegraph := [ (Sys.time (), 0.) ]
...@@ -421,6 +432,10 @@ let stop_doing_flamegraph callstack = ...@@ -421,6 +432,10 @@ let stop_doing_flamegraph callstack =
| [] -> assert false | [] -> assert false
| (_, total) :: q -> | (_, total) :: q ->
(* dump the total time (that we just updated) for the current function *) (* dump the total time (that we just updated) for the current function *)
let prev_total =
try EvaFlamegraph.find callstack with Not_found -> 0.0
in
EvaFlamegraph.replace callstack (prev_total +. total);
Printf.fprintf oc "%a %.3f\n%!" Printf.fprintf oc "%a %.3f\n%!"
pretty_callstack callstack (total *. 1000.); pretty_callstack callstack (total *. 1000.);
match q with match q with
...@@ -435,7 +450,9 @@ let stop_doing_flamegraph callstack = ...@@ -435,7 +450,9 @@ let stop_doing_flamegraph callstack =
let reset_flamegraph () = let reset_flamegraph () =
match !oc_flamegraph with match !oc_flamegraph with
| None -> () | None -> ()
| Some fd -> close_out fd; stack_flamegraph := []; oc_flamegraph := None | Some fd ->
close_out fd; stack_flamegraph := []; oc_flamegraph := None;
EvaFlamegraph.clear ()
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
......
...@@ -35,3 +35,6 @@ val display: Format.formatter -> unit ...@@ -35,3 +35,6 @@ val display: Format.formatter -> unit
(** Reset the internal state of the module; to call at the very (** Reset the internal state of the module; to call at the very
beginning of the analysis. *) beginning of the analysis. *)
val reset: unit -> unit val reset: unit -> unit
module EvaFlamegraph :
State_builder.Hashtbl with type key = Callstack.t and type data = float
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment