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

@ -41,7 +41,31 @@ type stats_type =
| Reporting | Reporting
| Driver | Driver
let dirname_of_stats_type = function 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 _ -> | ClangLinters _ ->
Config.frontend_stats_dir_name Config.frontend_stats_dir_name
| ClangFrontend _ -> | ClangFrontend _ ->
@ -58,6 +82,8 @@ let dirname_of_stats_type = function
Config.reporting_stats_dir_name Config.reporting_stats_dir_name
| Driver -> | Driver ->
Config.driver_stats_dir_name Config.driver_stats_dir_name
in
Filename.concat dirname filename
let string_of_stats_type = function let string_of_stats_type = function
@ -79,18 +105,6 @@ let string_of_stats_type = function
"driver" "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 to_json ps =
let time = let time =
Option.value_map ~default:[] ps.time ~f:(fun time_perf -> 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 registered = String.Table.create ~size:4 ()
let get_relative_path filename stats_type = let register_report stats_kind stats_type =
let dirname = dirname_of_stats_type stats_type in let relative_path = relative_path_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 absolute_path = Filename.concat Config.results_dir relative_path in let absolute_path = Filename.concat Config.results_dir relative_path in
let f = report stats_kind absolute_path stats_type in let f = report stats_kind absolute_path stats_type in
(* make sure to not double register the same perf stat report *) (* 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 dummy_reporter () = ()
let get_reporter filename stats_type = let get_reporter stats_type =
let relative_path = get_relative_path filename stats_type in let relative_path = relative_path_of_stats_type stats_type in
String.Table.find registered relative_path |> Option.value ~default:dummy_reporter String.Table.find registered relative_path |> Option.value ~default:dummy_reporter
let register_report_at_exit filename stats_type = let register_report_at_exit stats_type =
register_report TimeAndMemory filename stats_type ; let relative_path = relative_path_of_stats_type stats_type in
Epilogues.register register_report TimeAndMemory stats_type ;
~f:(get_reporter filename stats_type) Epilogues.register ~f:(get_reporter stats_type)
(string_of_stats_type stats_type ^ "stats reporting in " ^ filename) (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 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 *) (** 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 *) (** 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 *) (** 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 create_perf_stats_report source_file =
let abbrev_source_file = DB.source_file_encoding source_file in PerfStats.register_report PerfStats.TimeAndMemory (PerfStats.Backend source_file) ;
let filename = F.sprintf "%s_%s.json" Config.perf_stats_prefix abbrev_source_file in PerfStats.get_reporter (PerfStats.Backend source_file) ()
PerfStats.register_report PerfStats.TimeAndMemory filename (PerfStats.Backend source_file) ;
PerfStats.get_reporter filename (PerfStats.Backend source_file) ()
(** Invoke all procedure and cluster callbacks on a given environment. *) (** 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 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 = let stats_type =
match (Config.capture, Config.linters) with match (Config.capture, Config.linters) with
| true, true -> | true, true ->
@ -38,7 +36,7 @@ let register_perf_stats_report source_file =
| false, false -> | false, false ->
Logging.(die UserError) "Clang frontend should be run in capture and/or linters mode." Logging.(die UserError) "Clang frontend should be run in capture and/or linters mode."
in 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 = let init_global_state_for_capture_and_linters source_file =

@ -126,11 +126,6 @@ let clean_results_dir () =
delete_temp_results Config.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 reset_duplicates_file () =
let start = Config.results_dir ^/ Config.duplicates_filename in let start = Config.results_dir ^/ Config.duplicates_filename in
let delete () = Unix.unlink start in let delete () = Unix.unlink start in
@ -536,7 +531,7 @@ let mode_from_command_line =
let run_prologue mode = let run_prologue mode =
if CLOpt.is_originator then ( if CLOpt.is_originator then (
L.environment_info "%a@\n" Config.pp_version () ; 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.debug_mode then L.environment_info "Driver mode:@\n%a@." pp_mode mode ;
if Config.dump_duplicate_symbols then reset_duplicates_file () ; 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, (* 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 F = Format
module L = Logging 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 = let init_global_state source_file =
Language.curr_language := Language.Java ; 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 ; DB.Results_dir.init source_file ;
Ident.NameGenerator.reset () ; Ident.NameGenerator.reset () ;
JContext.reset_exn_node_table () JContext.reset_exn_node_table ()

Loading…
Cancel
Save