diff --git a/infer/src/base/PerfEvent.ml b/infer/src/base/PerfEvent.ml index 60a657a1f..89e2de033 100644 --- a/infer/src/base/PerfEvent.ml +++ b/infer/src/base/PerfEvent.ml @@ -239,14 +239,17 @@ let logger = let out_channel = Pervasives.open_out_gen [Open_append; Open_creat] 0o666 log_file in let logger = F.formatter_of_out_channel out_channel in register_gc_stats logger ; - if is_toplevel_process then ( + ( if is_toplevel_process then ( JsonFragment.pp logger ListBegin ; F.fprintf logger "%!" ; Epilogues.register_late ~description:"closing perf trace json" ~f:(fun () -> log_instant_event logger ~name:"end" Global ; JsonFragment.pp logger ListEnd ; F.fprintf logger "@." ; - Out_channel.close out_channel ) ) ; + Out_channel.close out_channel ) ) + else + (* assume the trace file is here and is ready to accept list elements *) + JsonFragment.(pp_state := InList :: !pp_state) ) ; logger) @@ -283,3 +286,6 @@ let log = let logger = Lazy.force logger in f_log logger else fun _ -> () + + +let init () = if Config.trace_events then ignore (Lazy.force logger) diff --git a/infer/src/base/PerfEvent.mli b/infer/src/base/PerfEvent.mli index 0d1598123..c3a006c89 100644 --- a/infer/src/base/PerfEvent.mli +++ b/infer/src/base/PerfEvent.mli @@ -42,3 +42,5 @@ val log_complete_event : val log_instant_event : logger -> ?timestamp:Mtime.t -> name:string -> scope -> unit val log : (logger -> unit) -> unit + +val init : unit -> unit diff --git a/infer/src/base/ResultsDir.ml b/infer/src/base/ResultsDir.ml index a4c5877df..31896f601 100644 --- a/infer/src/base/ResultsDir.ml +++ b/infer/src/base/ResultsDir.ml @@ -48,6 +48,7 @@ let remove_results_dir () = let prepare_logging_and_db () = L.setup_log_file () ; + PerfEvent.init () ; EventLogger.prepare () ; if Sys.is_file ResultsDatabase.database_fullpath <> `Yes then ResultsDatabase.create_db () ; ResultsDatabase.new_database_connection () diff --git a/infer/src/clang/Capture.ml b/infer/src/clang/Capture.ml index a92420c5f..703dd2dab 100644 --- a/infer/src/clang/Capture.ml +++ b/infer/src/clang/Capture.ml @@ -98,6 +98,14 @@ let run_clang_frontend ast_source = print_elapsed () +let run_clang_frontend ast_source = + PerfEvent.( + log (fun logger -> + PerfEvent.log_begin_event logger ~categories:["frontend"] ~name:"clang frontend" () )) ; + run_clang_frontend ast_source ; + PerfEvent.(log (fun logger -> PerfEvent.log_end_event logger ())) + + let run_and_validate_clang_frontend ast_source = try run_clang_frontend ast_source with exc -> IExn.reraise_if exc ~f:(fun () -> not Config.keep_going) ; @@ -121,6 +129,14 @@ let run_clang clang_command read = exit_with_error 1 +let run_clang clang_command read = + PerfEvent.( + log (fun logger -> PerfEvent.log_begin_event logger ~categories:["frontend"] ~name:"clang" ())) ; + let result = run_clang clang_command read in + PerfEvent.(log (fun logger -> PerfEvent.log_end_event logger ())) ; + result + + let run_plugin_and_frontend source_path frontend clang_cmd = let clang_plugin_cmd = ClangCommand.with_plugin_args clang_cmd in if debug_mode then (