@ -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_kind = Time of Mtime_clock . counter * Unix . process_times | Memory | TimeAndMemory
type stats_type =
type stats_type =
| ClangLinters
| ClangLinters of SourceFile . t
| ClangFrontend
| ClangFrontend of SourceFile . t
| ClangFrontendLinters
| ClangFrontendLinters of SourceFile . t
| JavaFrontend
| JavaFrontend of SourceFile . t
| PythonFrontend
| PythonFrontend of SourceFile . t
| Backend
| Backend of SourceFile . t
| Reporting
| Reporting
| Driver
| Driver
let dirname_of_stats_type = function
let dirname_of_stats_type = function
| ClangLinters ->
| ClangLinters _ ->
Config . frontend_stats_dir_name
Config . frontend_stats_dir_name
| ClangFrontend ->
| ClangFrontend _ ->
Config . frontend_stats_dir_name
Config . frontend_stats_dir_name
| ClangFrontendLinters ->
| ClangFrontendLinters _ ->
Config . frontend_stats_dir_name
Config . frontend_stats_dir_name
| JavaFrontend ->
| JavaFrontend _ ->
Config . frontend_stats_dir_name
Config . frontend_stats_dir_name
| PythonFrontend ->
| PythonFrontend _ ->
Config . frontend_stats_dir_name
Config . frontend_stats_dir_name
| Backend ->
| Backend _ ->
Config . backend_stats_dir_name
Config . backend_stats_dir_name
| Reporting ->
| Reporting ->
Config . reporting_stats_dir_name
Config . reporting_stats_dir_name
@ -61,17 +61,17 @@ let dirname_of_stats_type = function
let string_of_stats_type = function
let string_of_stats_type = function
| ClangLinters ->
| ClangLinters _ ->
" linters "
" linters "
| ClangFrontend ->
| ClangFrontend _ ->
" clang_frontend "
" clang_frontend "
| ClangFrontendLinters ->
| ClangFrontendLinters _ ->
" clang_frontend_and_linters "
" clang_frontend_and_linters "
| JavaFrontend ->
| JavaFrontend _ ->
" java_frontend "
" java_frontend "
| PythonFrontend ->
| PythonFrontend _ ->
" python_frontend "
" python_frontend "
| Backend ->
| Backend _ ->
" backend "
" backend "
| Reporting ->
| Reporting ->
" reporting "
" reporting "
@ -79,6 +79,18 @@ 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 ->
@ -254,7 +266,7 @@ let compute_time_stats ?rtime_counter (initial_times: Unix.process_times) =
( stats , time )
( stats , time )
let compute_stats stats_kind s ource_file s tats_type =
let compute_stats stats_kind s tats_type =
let ( mem , mem_perf ) , ( time , time_perf ) =
let ( mem , mem_perf ) , ( time , time_perf ) =
match stats_kind with
match stats_kind with
| Time ( rtime_counter , initial_times ) ->
| Time ( rtime_counter , initial_times ) ->
@ -268,7 +280,7 @@ let compute_stats stats_kind source_file stats_type =
let stats_event =
let stats_event =
EventLogger . PerformanceStats
EventLogger . PerformanceStats
{ lang = Language . to_explicit_string ! Language . curr_language
{ 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
; stats_type = string_of_stats_type stats_type
; mem_perf
; mem_perf
; time_perf }
; time_perf }
@ -276,9 +288,9 @@ let compute_stats stats_kind source_file stats_type =
( stats , stats_event )
( stats , stats_event )
let report stats_kind source_file file stats_type () =
let report stats_kind file stats_type () =
try
try
let stats , stats_event = compute_stats stats_kind s ource_file s tats_type in
let stats , stats_event = compute_stats stats_kind s tats_type in
let json_stats = to_json stats in
let json_stats = to_json stats in
EventLogger . log stats_event ;
EventLogger . log stats_event ;
(* We always log to EventLogger, but json files are unnecessary to log outside of developer mode *)
(* 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
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 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 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 *)
(* make sure to not double register the same perf stat report *)
match String . Table . add registered ~ key : relative_path ~ data : f with
match String . Table . add registered ~ key : relative_path ~ data : f with
| ` Ok ->
| ` Ok ->
@ -324,8 +336,8 @@ let get_reporter filename stats_type =
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 ? source_file filename stats_type =
let register_report_at_exit filename stats_type =
register_report TimeAndMemory ? source_file filename stats_type ;
register_report TimeAndMemory filename stats_type ;
Epilogues . register
Epilogues . register
~ f : ( get_reporter filename stats_type )
~ f : ( get_reporter filename stats_type )
( string_of_stats_type stats_type ^ " stats reporting in " ^ filename )
( string_of_stats_type stats_type ^ " stats reporting in " ^ filename )