[perf] fix capture traces and record clang events

Summary:
Trace events would crash when infer subprocesses were spawned by the build
system because they didn't detect if the file was already initialised
correctly.

Also trace the clang capture.

Reviewed By: mbouaziz

Differential Revision: D10380745

fbshipit-source-id: 76e1d4d7e
master
Jules Villard 6 years ago committed by Facebook Github Bot
parent fd660f42f5
commit bee7649048

@ -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)

@ -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

@ -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 ()

@ -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 (

Loading…
Cancel
Save