[reporting][perf] combine PerfStats source_file with stats_type

Summary: `stats_type` can just include a `SourceFile.t`, as the existence of a `source_file` parameter previously depended on the value of `stats_type` anyway

Reviewed By: dulmarod

Differential Revision: D7381605

fbshipit-source-id: 953ee27
master
Varun Arora 7 years ago committed by Facebook Github Bot
parent c29c636768
commit 24e66ada0b

@ -32,27 +32,27 @@ type perf_stats = {mem: mem_perf option; time: time_perf option}
type stats_kind = Time of Mtime_clock.counter * Unix.process_times | Memory | TimeAndMemory
type stats_type =
| ClangLinters
| ClangFrontend
| ClangFrontendLinters
| JavaFrontend
| PythonFrontend
| Backend
| ClangLinters of SourceFile.t
| ClangFrontend of SourceFile.t
| ClangFrontendLinters of SourceFile.t
| JavaFrontend of SourceFile.t
| PythonFrontend of SourceFile.t
| Backend of SourceFile.t
| Reporting
| Driver
let dirname_of_stats_type = function
| ClangLinters ->
| ClangLinters _ ->
Config.frontend_stats_dir_name
| ClangFrontend ->
| ClangFrontend _ ->
Config.frontend_stats_dir_name
| ClangFrontendLinters ->
| ClangFrontendLinters _ ->
Config.frontend_stats_dir_name
| JavaFrontend ->
| JavaFrontend _ ->
Config.frontend_stats_dir_name
| PythonFrontend ->
| PythonFrontend _ ->
Config.frontend_stats_dir_name
| Backend ->
| Backend _ ->
Config.backend_stats_dir_name
| Reporting ->
Config.reporting_stats_dir_name
@ -61,17 +61,17 @@ let dirname_of_stats_type = function
let string_of_stats_type = function
| ClangLinters ->
| ClangLinters _ ->
"linters"
| ClangFrontend ->
| ClangFrontend _ ->
"clang_frontend"
| ClangFrontendLinters ->
| ClangFrontendLinters _ ->
"clang_frontend_and_linters"
| JavaFrontend ->
| JavaFrontend _ ->
"java_frontend"
| PythonFrontend ->
| PythonFrontend _ ->
"python_frontend"
| Backend ->
| Backend _ ->
"backend"
| Reporting ->
"reporting"
@ -79,6 +79,18 @@ 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 ->
@ -254,7 +266,7 @@ let compute_time_stats ?rtime_counter (initial_times: Unix.process_times) =
(stats, time)
let compute_stats stats_kind source_file stats_type =
let compute_stats stats_kind stats_type =
let (mem, mem_perf), (time, time_perf) =
match stats_kind with
| Time (rtime_counter, initial_times) ->
@ -268,7 +280,7 @@ let compute_stats stats_kind source_file stats_type =
let stats_event =
EventLogger.PerformanceStats
{ lang= Language.to_explicit_string !Language.curr_language
; source_file
; source_file= source_file_of_stats_type stats_type
; stats_type= string_of_stats_type stats_type
; mem_perf
; time_perf }
@ -276,9 +288,9 @@ let compute_stats stats_kind source_file stats_type =
(stats, stats_event)
let report stats_kind source_file file stats_type () =
let report stats_kind file stats_type () =
try
let stats, stats_event = compute_stats stats_kind source_file stats_type in
let stats, stats_event = compute_stats stats_kind stats_type in
let json_stats = to_json stats in
EventLogger.log stats_event ;
(* We always log to EventLogger, but json files are unnecessary to log outside of developer mode *)
@ -305,10 +317,10 @@ let get_relative_path filename stats_type =
Filename.concat dirname filename
let register_report stats_kind ?source_file filename stats_type =
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 f = report stats_kind source_file 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 *)
match String.Table.add registered ~key:relative_path ~data:f with
| `Ok ->
@ -324,8 +336,8 @@ let get_reporter filename stats_type =
String.Table.find registered relative_path |> Option.value ~default:dummy_reporter
let register_report_at_exit ?source_file filename stats_type =
register_report TimeAndMemory ?source_file filename stats_type ;
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)

@ -16,12 +16,12 @@ type perf_stats
type stats_kind = Time of Mtime_clock.counter * Unix.process_times | Memory | TimeAndMemory
type stats_type =
| ClangLinters
| ClangFrontend
| ClangFrontendLinters
| JavaFrontend
| PythonFrontend
| Backend
| ClangLinters of SourceFile.t
| ClangFrontend of SourceFile.t
| ClangFrontendLinters of SourceFile.t
| JavaFrontend of SourceFile.t
| PythonFrontend of SourceFile.t
| Backend of SourceFile.t
| Reporting
| Driver
@ -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 -> ?source_file:SourceFile.t -> string -> stats_type -> unit
val register_report : stats_kind -> string -> stats_type -> unit
(** Register performance reporting function *)
val get_reporter : string -> stats_type -> unit -> unit
(** Get reporting function that can be called at any time to create a performance report *)
val register_report_at_exit : ?source_file:SourceFile.t -> string -> stats_type -> unit
val register_report_at_exit : string -> stats_type -> unit
(** Create performance report when the current process terminates *)

@ -122,8 +122,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 ~source_file filename PerfStats.Backend ;
PerfStats.get_reporter filename PerfStats.Backend ()
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. *)

@ -30,15 +30,15 @@ let register_perf_stats_report source_file =
let stats_type =
match (Config.capture, Config.linters) with
| true, true ->
PerfStats.ClangFrontendLinters
PerfStats.ClangFrontendLinters source_file
| true, false ->
PerfStats.ClangFrontend
PerfStats.ClangFrontend source_file
| false, true ->
PerfStats.ClangLinters
PerfStats.ClangLinters 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 ~source_file stats_type
PerfStats.register_report_at_exit filename stats_type
let init_global_state_for_capture_and_linters source_file =

@ -17,7 +17,7 @@ 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 ~source_file PerfStats.JavaFrontend
PerfStats.register_report_at_exit filename (PerfStats.JavaFrontend source_file)
let init_global_state source_file =

Loading…
Cancel
Save