Skip to content

Commit

Permalink
[multicore] thread safe analysis stats
Browse files Browse the repository at this point in the history
Summary: As per title

Reviewed By: davidpichardie

Differential Revision:
D67969063

Privacy Context Container: L1208441

fbshipit-source-id: a1b731fe08f82ee352a9a5698f02b8a50d751e68
  • Loading branch information
ngorogiannis authored and facebook-github-bot committed Jan 9, 2025
1 parent a564e65 commit fc1daaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion infer/src/backend/MulticoreAnalyze.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ let run_analysis replay_call_graph source_files_to_analyze_lazy =
L.debug Analysis Quiet "Multicore analysis starting...@." ;
if Option.is_some replay_call_graph then
L.die UserError "Multicore analysis does not support the replay scheduler.@\n" ;
let pre_analysis_gc_stats = GCStats.get ~since:ProgramStart in
Lazy.force source_files_to_analyze_lazy |> List.iter ~f:TargetStack.push ;
Database.db_close () ;
let n_workers = min (Domain.recommended_domain_count () - 1) (TargetStack.length ()) in
Expand All @@ -63,4 +64,6 @@ let run_analysis replay_call_graph source_files_to_analyze_lazy =
L.debug Analysis Quiet "Multicore analysis spawned %d domains.@." n_workers ;
List.iter workers ~f:Domain.join ;
L.debug Analysis Quiet "Multicore analysis finished.@." ;
([], [], [])
( [Stats.get ()]
, [GCStats.get ~since:(PreviousStats pre_analysis_gc_stats)]
, [MissingDependencies.get ()] )
10 changes: 8 additions & 2 deletions infer/src/base/Stats.ml
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,20 @@ let log_aggregate stats_list =
log_to_file stats


let get () = {global_stats with timings= TimingsStat.serialize global_stats.timings}
let mutex = Error_checking_mutex.create ()

let get () =
Error_checking_mutex.critical_section mutex ~f:(fun () ->
{global_stats with timings= TimingsStat.serialize global_stats.timings} )


let update_with field ~f =
match Field.setter field with
| None ->
L.die InternalError "incr on non-mutable field %s" (Field.name field)
| Some set ->
set global_stats (f (Field.get field global_stats))
Error_checking_mutex.critical_section mutex ~f:(fun () ->
set global_stats (f (Field.get field global_stats)) )


let add field n = update_with field ~f:(( + ) n)
Expand Down

0 comments on commit fc1daaa

Please sign in to comment.