[reporting][perf] PerfStats directly resolves filename - no need to pass as parameter

Summary:
- PerfStats can now directly compute the filename / relative path of the stats to be logged
	- There is no longer a need to pass in the filename as a parameter, simplifying the API to just be a one-liner

Reviewed By: dulmarod

Differential Revision: D7381886

fbshipit-source-id: e6623c3
master
Varun Arora 7 years ago committed by Facebook Github Bot
parent 24e66ada0b
commit 00744a888a

@ -965,14 +965,8 @@ let pp_summary_and_issues formats_by_report_kind issue_formats =
let register_perf_stats_report () =
let fname = F.sprintf "%s.json" Config.perf_stats_prefix in
let rtime_span, initial_times = (Mtime_clock.counter (), Unix.times ()) in
PerfStats.register_report (PerfStats.Time (rtime_span, initial_times)) fname PerfStats.Reporting
let report_perf_stats () =
let fname = F.sprintf "%s.json" Config.perf_stats_prefix in
PerfStats.get_reporter fname PerfStats.Reporting ()
PerfStats.register_report (PerfStats.Time (rtime_span, initial_times)) PerfStats.Reporting
let main ~report_json =
@ -990,4 +984,4 @@ let main ~report_json =
pp_json_report_by_report_kind formats_by_report_kind fname
| None ->
pp_summary_and_issues formats_by_report_kind issue_formats ) ;
report_perf_stats ()
PerfStats.get_reporter PerfStats.Reporting ()

@ -41,23 +41,49 @@ type stats_type =
| Reporting
| Driver
let dirname_of_stats_type = function
| ClangLinters _ ->
Config.frontend_stats_dir_name
| ClangFrontend _ ->
Config.frontend_stats_dir_name
| ClangFrontendLinters _ ->
Config.frontend_stats_dir_name
| JavaFrontend _ ->
Config.frontend_stats_dir_name
| PythonFrontend _ ->
Config.frontend_stats_dir_name
| Backend _ ->
Config.backend_stats_dir_name
| Reporting ->
Config.reporting_stats_dir_name
| Driver ->
Config.driver_stats_dir_name
let source_file_of_stats_type = function
| ClangLinters source_file
| ClangFrontend source_file
| ClangFrontendLinters source_file
| JavaFrontend source_file
| PythonFrontend source_file
| Backend source_file ->
Some source_file
| _ ->
None
let relative_path_of_stats_type stats_type =
let abbrev_source_file =
Option.map ~f:DB.source_file_encoding (source_file_of_stats_type stats_type)
in
let filename =
match abbrev_source_file with
| Some abbrev ->
F.sprintf "%s_%s.json" Config.perf_stats_prefix abbrev
| None ->
F.sprintf "%s.json" Config.perf_stats_prefix
in
let dirname =
match stats_type with
| ClangLinters _ ->
Config.frontend_stats_dir_name
| ClangFrontend _ ->
Config.frontend_stats_dir_name
| ClangFrontendLinters _ ->
Config.frontend_stats_dir_name
| JavaFrontend _ ->
Config.frontend_stats_dir_name
| PythonFrontend _ ->
Config.frontend_stats_dir_name
| Backend _ ->
Config.backend_stats_dir_name
| Reporting ->
Config.reporting_stats_dir_name
| Driver ->
Config.driver_stats_dir_name
in
Filename.concat dirname filename
let string_of_stats_type = function
@ -79,18 +105,6 @@ let string_of_stats_type = function
"driver"
let source_file_of_stats_type = function
| ClangLinters source_file
| ClangFrontend source_file
| ClangFrontendLinters source_file
| JavaFrontend source_file
| PythonFrontend source_file
| Backend source_file ->
Some source_file
| _ ->
None
let to_json ps =
let time =
Option.value_map ~default:[] ps.time ~f:(fun time_perf ->
@ -312,13 +326,8 @@ let report stats_kind file stats_type () =
let registered = String.Table.create ~size:4 ()
let get_relative_path filename stats_type =
let dirname = dirname_of_stats_type stats_type in
Filename.concat dirname filename
let register_report stats_kind filename stats_type =
let relative_path = get_relative_path filename stats_type in
let register_report stats_kind stats_type =
let relative_path = relative_path_of_stats_type stats_type in
let absolute_path = Filename.concat Config.results_dir relative_path in
let f = report stats_kind absolute_path stats_type in
(* make sure to not double register the same perf stat report *)
@ -331,13 +340,13 @@ let register_report stats_kind filename stats_type =
let dummy_reporter () = ()
let get_reporter filename stats_type =
let relative_path = get_relative_path filename stats_type in
let get_reporter stats_type =
let relative_path = relative_path_of_stats_type stats_type in
String.Table.find registered relative_path |> Option.value ~default:dummy_reporter
let register_report_at_exit filename stats_type =
register_report TimeAndMemory filename stats_type ;
Epilogues.register
~f:(get_reporter filename stats_type)
(string_of_stats_type stats_type ^ "stats reporting in " ^ filename)
let register_report_at_exit stats_type =
let relative_path = relative_path_of_stats_type stats_type in
register_report TimeAndMemory stats_type ;
Epilogues.register ~f:(get_reporter stats_type)
(string_of_stats_type stats_type ^ "stats reporting in " ^ relative_path)

@ -29,11 +29,11 @@ val from_json : Yojson.Basic.json -> perf_stats
val aggregate : perf_stats list -> Yojson.Basic.json
val register_report : stats_kind -> string -> stats_type -> unit
val register_report : stats_kind -> stats_type -> unit
(** Register performance reporting function *)
val get_reporter : string -> stats_type -> unit -> unit
val get_reporter : stats_type -> unit -> unit
(** Get reporting function that can be called at any time to create a performance report *)
val register_report_at_exit : string -> stats_type -> unit
val register_report_at_exit : stats_type -> unit
(** Create performance report when the current process terminates *)

@ -120,10 +120,8 @@ let dump_duplicate_procs (exe_env: Exe_env.t) procs =
let create_perf_stats_report source_file =
let abbrev_source_file = DB.source_file_encoding source_file in
let filename = F.sprintf "%s_%s.json" Config.perf_stats_prefix abbrev_source_file in
PerfStats.register_report PerfStats.TimeAndMemory filename (PerfStats.Backend source_file) ;
PerfStats.get_reporter filename (PerfStats.Backend source_file) ()
PerfStats.register_report PerfStats.TimeAndMemory (PerfStats.Backend source_file) ;
PerfStats.get_reporter (PerfStats.Backend source_file) ()
(** Invoke all procedure and cluster callbacks on a given environment. *)

@ -25,8 +25,6 @@ let validate_decl_from_channel chan =
let register_perf_stats_report source_file =
let abbrev_source_file = DB.source_file_encoding source_file in
let filename = F.sprintf "%s_%s.json" Config.perf_stats_prefix abbrev_source_file in
let stats_type =
match (Config.capture, Config.linters) with
| true, true ->
@ -38,7 +36,7 @@ let register_perf_stats_report source_file =
| false, false ->
Logging.(die UserError) "Clang frontend should be run in capture and/or linters mode."
in
PerfStats.register_report_at_exit filename stats_type
PerfStats.register_report_at_exit stats_type
let init_global_state_for_capture_and_linters source_file =

@ -126,11 +126,6 @@ let clean_results_dir () =
delete_temp_results Config.results_dir
let register_perf_stats_report () =
let filename = F.sprintf "%s.json" Config.perf_stats_prefix in
PerfStats.register_report_at_exit filename PerfStats.Driver
let reset_duplicates_file () =
let start = Config.results_dir ^/ Config.duplicates_filename in
let delete () = Unix.unlink start in
@ -536,7 +531,7 @@ let mode_from_command_line =
let run_prologue mode =
if CLOpt.is_originator then (
L.environment_info "%a@\n" Config.pp_version () ;
register_perf_stats_report () ) ;
PerfStats.register_report_at_exit PerfStats.Driver ) ;
if Config.debug_mode then L.environment_info "Driver mode:@\n%a@." pp_mode mode ;
if Config.dump_duplicate_symbols then reset_duplicates_file () ;
(* infer might be called from a Makefile and itself uses `make` to run the analysis in parallel,

@ -14,15 +14,9 @@ open Javalib_pack
module F = Format
module L = Logging
let register_perf_stats_report source_file =
let abbrev_source_file = DB.source_file_encoding source_file in
let filename = F.sprintf "%s_%s.json" Config.perf_stats_prefix abbrev_source_file in
PerfStats.register_report_at_exit filename (PerfStats.JavaFrontend source_file)
let init_global_state source_file =
Language.curr_language := Language.Java ;
register_perf_stats_report source_file ;
PerfStats.register_report_at_exit (PerfStats.JavaFrontend source_file) ;
DB.Results_dir.init source_file ;
Ident.NameGenerator.reset () ;
JContext.reset_exn_node_table ()

Loading…
Cancel
Save