From 0554da99e71e9bbcd4cc30b7ad7ce622c40598f7 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 15 Jun 2017 05:03:47 -0700 Subject: [PATCH] [perfstats] do not register the same file twice in the same process Summary: Only one instance will win in the end so it's not useful to double register. Log when that happens. Currently it happens in the Java tests on `InferBuiltins` but I don't understand why so I left it alone. Reviewed By: jberdine Differential Revision: D5217928 fbshipit-source-id: dc7ccca --- infer/src/backend/PerfStats.ml | 44 ++++++++++++++++++++-------------- infer/src/java/jClasspath.mli | 2 +- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/infer/src/backend/PerfStats.ml b/infer/src/backend/PerfStats.ml index d1ade44b9..25bc0c2df 100644 --- a/infer/src/backend/PerfStats.ml +++ b/infer/src/backend/PerfStats.ml @@ -142,21 +142,29 @@ let stats () = attributes_table = at } -let register_report_at_exit file = - if not Config.buck_cache_mode then - Epilogues.register ~f:(fun () -> - try - let json_stats = to_json (stats ()) in - try - Unix.mkdir_p (Filename.dirname file); - Utils.write_file_with_locking file ~f:(fun stats_oc -> - Yojson.Basic.pretty_to_channel stats_oc json_stats; - ); - with exc -> - L.internal_error "Info: failed to write stats to %s@\n%s@\n%s@\n%s@." - file (Exn.to_string exc) (Yojson.Basic.pretty_to_string json_stats) - (Printexc.get_backtrace ()) - with exc -> - L.internal_error "Info: failed to compute stats for %s@\n%s@\n%s@." - file (Exn.to_string exc) (Printexc.get_backtrace ()) - ) ("stats reporting in " ^ file) +let report_at_exit file () = + try + let json_stats = to_json (stats ()) in + try + Unix.mkdir_p (Filename.dirname file); + (* the same report may be registered across different infer processes *) + Utils.write_file_with_locking file ~f:(fun stats_oc -> + Yojson.Basic.pretty_to_channel stats_oc json_stats; + ); + with exc -> + L.internal_error "Info: failed to write stats to %s@\n%s@\n%s@\n%s@." + file (Exn.to_string exc) (Yojson.Basic.pretty_to_string json_stats) + (Printexc.get_backtrace ()) + with exc -> + L.internal_error "Info: failed to compute stats for %s@\n%s@\n%s@." + file (Exn.to_string exc) (Printexc.get_backtrace ()) + +let register_report_at_exit = + (* take care of not double-registering the same perf stat report *) + let registered_files = String.Table.create ~size:4 () in + fun file -> + if not (Hashtbl.mem registered_files file) then ( + String.Table.set registered_files ~key:file ~data:(); + if not Config.buck_cache_mode then + Epilogues.register ~f:(report_at_exit file) ("stats reporting in " ^ file) + ) diff --git a/infer/src/java/jClasspath.mli b/infer/src/java/jClasspath.mli index c6fb70caf..f59abb292 100644 --- a/infer/src/java/jClasspath.mli +++ b/infer/src/java/jClasspath.mli @@ -27,7 +27,7 @@ val is_model : Typ.Procname.t -> bool val split_classpath : string -> string list -(** map entry for source files with potential basname collision within the same compiler call *) +(** map entry for source files with potential basename collision within the same compiler call *) type file_entry = | Singleton of SourceFile.t | Duplicate of (string * SourceFile.t) list