@ -23,12 +23,7 @@ include struct
; mutable proc_locker_lock_time : ExecutionDuration . t
; mutable proc_locker_unlock_time : ExecutionDuration . t
; mutable restart_scheduler_useful_time : ExecutionDuration . t
; mutable restart_scheduler_total_time : ExecutionDuration . t
; mutable scheduler_process_analysis_time : ExecutionDuration . t
(* * - [scheduler_process_analysis_time.wall] counts the wall time of the analysis phase
- [ scheduler_process_analysis_time . ( user | sys ) ] counts the [ ( user | sys ) ] time only of
the scheduler_process * )
; mutable gc_stats : GCStats . t option }
; mutable restart_scheduler_total_time : ExecutionDuration . t }
[ @@ deriving fields ]
end
@ -43,9 +38,7 @@ let global_stats =
; proc_locker_lock_time = ExecutionDuration . zero
; proc_locker_unlock_time = ExecutionDuration . zero
; restart_scheduler_useful_time = ExecutionDuration . zero
; restart_scheduler_total_time = ExecutionDuration . zero
; scheduler_process_analysis_time = ExecutionDuration . zero
; gc_stats = None }
; restart_scheduler_total_time = ExecutionDuration . zero }
let get () = global_stats
@ -92,11 +85,6 @@ let add_to_restart_scheduler_total_time execution_duration =
add Fields . restart_scheduler_total_time execution_duration
let set_analysis_time stats execution_duration =
let set_opt = Field . setter Fields . scheduler_process_analysis_time in
Option . iter set_opt ~ f : ( fun set -> set stats execution_duration )
let copy from ~ into : unit =
let { summary_file_try_load
; summary_read_from_disk
@ -108,16 +96,13 @@ let copy from ~into : unit =
; proc_locker_lock_time
; proc_locker_unlock_time
; restart_scheduler_useful_time
; restart_scheduler_total_time
; scheduler_process_analysis_time
; gc_stats } =
; restart_scheduler_total_time } =
from
in
Fields . Direct . set_all_mutable_fields into ~ summary_file_try_load ~ summary_read_from_disk
~ summary_cache_hits ~ summary_cache_misses ~ ondemand_procs_analyzed ~ ondemand_local_cache_hits
~ ondemand_local_cache_misses ~ proc_locker_lock_time ~ proc_locker_unlock_time
~ restart_scheduler_useful_time ~ restart_scheduler_total_time ~ scheduler_process_analysis_time
~ gc_stats
~ restart_scheduler_useful_time ~ restart_scheduler_total_time
let merge stats1 stats2 =
@ -138,8 +123,7 @@ let merge stats1 stats2 =
stats2 . restart_scheduler_useful_time
; restart_scheduler_total_time =
ExecutionDuration . add stats1 . restart_scheduler_total_time stats2 . restart_scheduler_total_time
; scheduler_process_analysis_time = ExecutionDuration . zero
; gc_stats = Option . merge stats1 . gc_stats stats2 . gc_stats ~ f : GCStats . merge }
}
let initial =
@ -153,22 +137,12 @@ let initial =
; proc_locker_lock_time = ExecutionDuration . zero
; proc_locker_unlock_time = ExecutionDuration . zero
; restart_scheduler_useful_time = ExecutionDuration . zero
; restart_scheduler_total_time = ExecutionDuration . zero
; scheduler_process_analysis_time = ExecutionDuration . zero
; gc_stats = None }
; restart_scheduler_total_time = ExecutionDuration . zero }
let reset () =
copy initial ~ into : global_stats ;
global_stats . gc_stats <- Some ( GCStats . get ~ since : ProgramStart )
let reset () = copy initial ~ into : global_stats
let pp f stats =
let pp_field pp_value stats f field =
let field_value = Field . get field stats in
let field_name = Field . name field in
F . fprintf f " %s = %a@; " field_name pp_value field_value
in
let pp_hit_percent hit miss f =
let total = hit + miss in
if Int . equal total 0 then F . pp_print_string f " N/A%% " else F . fprintf f " %d%% " ( hit * 100 / total )
@ -179,7 +153,7 @@ let pp f stats =
let pp_execution_duration_field stats f field =
let field_value = Field . get field stats in
let field_name = Field . name field in
F . fprintf f " %a@; " ( ExecutionDuration . pp ~ field : field_name ) field_value
F . fprintf f " %a@; " ( ExecutionDuration . pp ~ prefix : field_name ) field_value
in
let pp_cache_hits stats cache_misses f cache_hits_field =
let cache_hits = Field . get cache_hits_field stats in
@ -197,8 +171,6 @@ let pp f stats =
~ proc_locker_unlock_time : ( pp_execution_duration_field stats f )
~ restart_scheduler_useful_time : ( pp_execution_duration_field stats f )
~ restart_scheduler_total_time : ( pp_execution_duration_field stats f )
~ scheduler_process_analysis_time : ( pp_execution_duration_field stats f )
~ gc_stats : ( pp_field ( Pp . option GCStats . pp ) stats f )
in
F . fprintf f " @[Backend stats:@ \n @[<v2> %t@]@]@. " ( pp_stats stats )
@ -207,21 +179,9 @@ let log_to_scuba stats =
let create_counter field =
[ LogEntry . mk_count ~ label : ( " backend_stats. " ^ Field . name field ) ~ value : ( Field . get field stats ) ]
in
let secs_to_ms s = s * . 1000 . | > Float . to_int in
let create_time_entry field =
let field_value = Field . get field stats in
[ LogEntry . mk_time
~ label : ( " backend_stats. " ^ Field . name field ^ " _sys " )
~ duration_ms : ( ExecutionDuration . sys_time field_value | > secs_to_ms )
; LogEntry . mk_time
~ label : ( " backend_stats. " ^ Field . name field ^ " _user " )
~ duration_ms : ( ExecutionDuration . user_time field_value | > secs_to_ms )
; LogEntry . mk_time
~ label : ( " backend_stats. " ^ Field . name field ^ " _wall " )
~ duration_ms : ( ExecutionDuration . wall_time field_value | > secs_to_ms ) ]
in
let create_scuba_option scuba_creator field =
match Field . get field stats with None -> [] | Some value -> scuba_creator value
Field . get field stats
| > ExecutionDuration . to_scuba_entries ~ prefix : ( " backend_stats. " ^ Field . name field )
in
let entries =
Fields . to_list ~ summary_file_try_load : create_counter ~ summary_read_from_disk : create_counter
@ -230,8 +190,16 @@ let log_to_scuba stats =
~ ondemand_local_cache_misses : create_counter ~ proc_locker_lock_time : create_time_entry
~ proc_locker_unlock_time : create_time_entry ~ restart_scheduler_useful_time : create_time_entry
~ restart_scheduler_total_time : create_time_entry
~ scheduler_process_analysis_time : create_time_entry
~ gc_stats : ( create_scuba_option ( GCStats . to_scuba_entries ~ prefix : " backend " ) )
| > List . concat
in
ScubaLogging . log_many entries
let log_aggregate stats_list =
match stats_list with
| [] ->
L . internal_error " Empty list of backend stats to aggregate, weird!@ \n "
| one :: rest ->
let stats = List . fold rest ~ init : one ~ f : ( fun aggregate one -> merge aggregate one ) in
L . debug Analysis Quiet " %a " pp stats ;
log_to_scuba stats