Report time and memory stats

Summary:public
Report statistics on consumed time and memory in results_dir/perf_stats.json.

Reviewed By: martinoluca

Differential Revision: D3162381

fb-gh-sync-id: e802faa
fbshipit-source-id: e802faa
master
Josh Berdine 9 years ago committed by Facebook Github Bot 2
parent 6b2b76d956
commit a5e1a6c77e

@ -0,0 +1,37 @@
(*
* Copyright (c) 2016 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*)
(** Performance Statistics gathering and reporting *)
open! Utils
let register_report_at_exit file =
Pervasives.at_exit (fun () ->
let gc_stats = Gc.quick_stat () in
let exit_timeofday = Unix.gettimeofday () in
let exit_times = Unix.times () in
let stats =
`Assoc [
("rtime", `Float (exit_timeofday -. initial_timeofday)) ;
("utime", `Float (exit_times.tms_utime -. initial_times.tms_utime)) ;
("stime", `Float (exit_times.tms_stime -. initial_times.tms_stime)) ;
("cutime", `Float (exit_times.tms_cutime -. initial_times.tms_cutime)) ;
("cstime", `Float (exit_times.tms_cstime -. initial_times.tms_cstime)) ;
("minor_words", `Float gc_stats.minor_words) ;
("promoted_words", `Float gc_stats.promoted_words) ;
("major_words", `Float gc_stats.major_words) ;
("minor_collections", `Int gc_stats.minor_collections) ;
("major_collections", `Int gc_stats.major_collections) ;
("compactions", `Int gc_stats.compactions) ;
("top_heap_words", `Int gc_stats.top_heap_words) ;
] in
let stats_oc = open_out file in
Yojson.Basic.pretty_to_channel stats_oc stats ;
close_out stats_oc
)

@ -0,0 +1,14 @@
(*
* Copyright (c) 2016 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*)
(** Performance Statistics gathering and reporting *)
open! Utils
val register_report_at_exit : string -> unit

@ -37,6 +37,10 @@ let attributes_dir_name = "attributes"
let captured_dir_name = "captured"
let sources_dir_name = "sources"
let specs_dir_name = "specs"
let perf_stats_prefix = "perf_stats"
let backend_stats_dir_name = "backend_stats"
let frontend_stats_dir_name = "frontend_stats"
let reporting_stats_dir_name = "reporting_stats"
let default_in_zip_results_dir = "infer"

@ -353,7 +353,17 @@ let process_cluster_cmdline fname =
| Some (nr, cluster) ->
analyze_cluster (nr - 1) cluster
let register_perf_stats_report () =
let stats_dir = Filename.concat !Config.results_dir Config.backend_stats_dir_name in
let cluster = match !cluster_cmdline with Some cl -> "_" ^ cl | None -> "" in
let stats_file = Filename.concat stats_dir (Config.perf_stats_prefix ^ cluster ^ ".json") in
DB.create_dir !Config.results_dir ;
DB.create_dir stats_dir ;
PerfStats.register_report_at_exit stats_file
let () =
register_perf_stats_report () ;
if !Config.developer_mode then
Printexc.record_backtrace true;
print_prolog ();

@ -1140,7 +1140,16 @@ end
(* warning: computing top procedures iterates over summaries twice *)
let compute_top_procedures = ref false
let register_perf_stats_report () =
let stats_dir = Filename.concat !Config.results_dir Config.reporting_stats_dir_name in
let stats_file = Filename.concat stats_dir (Config.perf_stats_prefix ^ ".json") in
DB.create_dir !Config.results_dir ;
DB.create_dir stats_dir ;
PerfStats.register_report_at_exit stats_file
let () =
register_perf_stats_report () ;
Config.developer_mode := true;
Config.print_using_diff := true;
handle_source_file_copy_option ();

@ -16,6 +16,12 @@ module F = Format
functions and builtin equality. Use IList instead. *)
module List = struct end
(** initial process times *)
let initial_times = Unix.times ()
(** precise time of day at the start of the analysis *)
let initial_timeofday = Unix.gettimeofday ()
(** {2 Generic Utility Functions} *)
(** Compare police: generic compare disabled. *)
@ -226,9 +232,6 @@ let pp_current_time f () =
let tm = Unix.localtime (Unix.time ()) in
F.fprintf f "%02d/%02d/%4d %02d:%02d" tm.Unix.tm_mday tm.Unix.tm_mon (tm.Unix.tm_year + 1900) tm.Unix.tm_hour tm.Unix.tm_min
(** precise time of day at the start of the analysis *)
let initial_timeofday = Unix.gettimeofday ()
(** Print the time in seconds elapsed since the beginning of the execution of the current command. *)
let pp_elapsed_time fmt () =
let elapsed = Unix.gettimeofday () -. initial_timeofday in

@ -16,6 +16,12 @@
functions and builtin equality. Use IList instead. *)
module List : sig end
(** initial process times *)
val initial_times : Unix.process_times
(** precise time of day at the start of the analysis *)
val initial_timeofday : float
(** Compare police: generic compare disabled. *)
val compare : unit
@ -142,6 +148,7 @@ val pp_current_time : Format.formatter -> unit -> unit
(** Print the time in seconds elapsed since the beginning of the execution of the current command. *)
val pp_elapsed_time : Format.formatter -> unit -> unit
module Arg : sig
include module type of Arg with type spec = Arg.spec

@ -33,7 +33,16 @@ let compute_icfg tenv ast =
(cg, cfg)
| _ -> assert false (* NOTE: Assumes that an AST alsways starts with a TranslationUnitDecl *)
let register_perf_stats_report source_file =
let stats_dir = Filename.concat !Config.results_dir Config.frontend_stats_dir_name in
let abbrev_source_file = DB.source_file_encoding source_file in
let stats_file = Config.perf_stats_prefix ^ "_" ^ abbrev_source_file ^ ".json" in
DB.create_dir !Config.results_dir ;
DB.create_dir stats_dir ;
PerfStats.register_report_at_exit (Filename.concat stats_dir stats_file)
let init_global_state source_file =
register_perf_stats_report source_file ;
Config.curr_language := Config.C_CPP;
DB.current_source := source_file;
DB.Results_dir.init ();

@ -87,7 +87,17 @@ let () =
failwith "Java model file is required"
let register_perf_stats_report source_file =
let stats_dir = Filename.concat !Config.results_dir Config.frontend_stats_dir_name in
let abbrev_source_file = DB.source_file_encoding source_file in
let stats_file = Config.perf_stats_prefix ^ "_" ^ abbrev_source_file ^ ".json" in
DB.create_dir !Config.results_dir ;
DB.create_dir stats_dir ;
PerfStats.register_report_at_exit (Filename.concat stats_dir stats_file)
let init_global_state source_file =
register_perf_stats_report source_file ;
Config.curr_language := Config.Java;
DB.current_source := source_file;
DB.Results_dir.init ();

@ -33,6 +33,14 @@ let print_usage_exit () =
Arg.usage arg_desc usage;
exit(1)
let register_perf_stats_report source_file =
let stats_dir = Filename.concat !Config.results_dir Config.frontend_stats_dir_name in
let abbrev_source_file = DB.source_file_encoding source_file in
let stats_file = Config.perf_stats_prefix ^ "_" ^ abbrev_source_file ^ ".json" in
DB.create_dir !Config.results_dir ;
DB.create_dir stats_dir ;
PerfStats.register_report_at_exit (Filename.concat stats_dir stats_file)
let init_global_state source_filename =
Config.curr_language := Config.C_CPP;
begin match !Config.project_root with
@ -41,6 +49,7 @@ let init_global_state source_filename =
DB.current_source := DB.rel_source_file_from_abs_path project_root
(filename_to_absolute source_filename)
end;
register_perf_stats_report !DB.current_source ;
DB.Results_dir.init ();
Ident.NameGenerator.reset ();
Config.nLOC := FileLOC.file_get_loc source_filename

Loading…
Cancel
Save