[callbacks] trace each checker's execution time

Summary: Use `PerfEvent` to record the execution time of individual checkers.

Reviewed By: jeremydubreil, mbouaziz

Differential Revision: D9832102

fbshipit-source-id: 678fca155
master
Jules Villard 6 years ago committed by Facebook Github Bot
parent 6837629654
commit d5c59743b7

@ -24,20 +24,22 @@ type cluster_callback_args =
type cluster_callback_t = cluster_callback_args -> unit type cluster_callback_t = cluster_callback_args -> unit
type procedure_callback = {dynamic_dispatch: bool; language: Language.t; callback: proc_callback_t} type procedure_callback =
{name: string; dynamic_dispatch: bool; language: Language.t; callback: proc_callback_t}
type cluster_callback = {language: Language.t; callback: cluster_callback_t} type cluster_callback = {name: string; language: Language.t; callback: cluster_callback_t}
let procedure_callbacks = ref [] let procedure_callbacks = ref []
let cluster_callbacks = ref [] let cluster_callbacks = ref []
let register_procedure_callback ?(dynamic_dispatch = false) language (callback : proc_callback_t) = let register_procedure_callback ~name ?(dynamic_dispatch = false) language
procedure_callbacks := {dynamic_dispatch; language; callback} :: !procedure_callbacks (callback : proc_callback_t) =
procedure_callbacks := {name; dynamic_dispatch; language; callback} :: !procedure_callbacks
let register_cluster_callback language (callback : cluster_callback_t) = let register_cluster_callback ~name language (callback : cluster_callback_t) =
cluster_callbacks := {language; callback} :: !cluster_callbacks cluster_callbacks := {name; language; callback} :: !cluster_callbacks
(** Collect what we need to know about a procedure for the analysis. *) (** Collect what we need to know about a procedure for the analysis. *)
@ -64,9 +66,17 @@ let iterate_procedure_callbacks exe_env summary proc_desc =
let tenv = Exe_env.get_tenv exe_env proc_name in let tenv = Exe_env.get_tenv exe_env proc_name in
let is_specialized = Procdesc.is_specialized proc_desc in let is_specialized = Procdesc.is_specialized proc_desc in
List.fold ~init:summary List.fold ~init:summary
~f:(fun summary {dynamic_dispatch; language; callback} -> ~f:(fun summary {name; dynamic_dispatch; language; callback} ->
if Language.equal language procedure_language && (dynamic_dispatch || not is_specialized) if Language.equal language procedure_language && (dynamic_dispatch || not is_specialized)
then callback {get_procs_in_file; tenv; summary; proc_desc; exe_env} then (
PerfEvent.(
log (fun logger ->
log_begin_event logger ~name ~categories:["backend"]
~arguments:[("proc", `String (Typ.Procname.to_string proc_name))]
() )) ;
let summary = callback {get_procs_in_file; tenv; summary; proc_desc; exe_env} in
PerfEvent.(log (fun logger -> log_end_event logger ())) ;
summary )
else summary ) else summary )
!procedure_callbacks !procedure_callbacks

@ -28,10 +28,11 @@ type cluster_callback_args =
type cluster_callback_t = cluster_callback_args -> unit type cluster_callback_t = cluster_callback_args -> unit
val register_procedure_callback : ?dynamic_dispatch:bool -> Language.t -> proc_callback_t -> unit val register_procedure_callback :
name:string -> ?dynamic_dispatch:bool -> Language.t -> proc_callback_t -> unit
(** register a procedure callback *) (** register a procedure callback *)
val register_cluster_callback : Language.t -> cluster_callback_t -> unit val register_cluster_callback : name:string -> Language.t -> cluster_callback_t -> unit
(** register a cluster callback *) (** register a cluster callback *)
val analyze_file : Exe_env.t -> SourceFile.t -> unit val analyze_file : Exe_env.t -> SourceFile.t -> unit

@ -124,15 +124,15 @@ let get_active_checkers () =
let register checkers = let register checkers =
let register_one {callbacks} = let register_one {name; callbacks} =
let register_callback (callback, language) = let register_callback (callback, language) =
match callback with match callback with
| Procedure procedure_cb -> | Procedure procedure_cb ->
Callbacks.register_procedure_callback language procedure_cb Callbacks.register_procedure_callback ~name language procedure_cb
| DynamicDispatch procedure_cb -> | DynamicDispatch procedure_cb ->
Callbacks.register_procedure_callback ~dynamic_dispatch:true language procedure_cb Callbacks.register_procedure_callback ~name ~dynamic_dispatch:true language procedure_cb
| Cluster cluster_cb -> | Cluster cluster_cb ->
Callbacks.register_cluster_callback language cluster_cb Callbacks.register_cluster_callback ~name language cluster_cb
in in
List.iter ~f:register_callback callbacks List.iter ~f:register_callback callbacks
in in

Loading…
Cancel
Save