[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
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent a84df4673a
commit 0554da99e7

@ -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)
)

@ -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

Loading…
Cancel
Save