From 546eaa0eaab3d3593c91a597065f934ef311afe4 Mon Sep 17 00:00:00 2001 From: Samuel Blackshear Date: Tue, 15 Dec 2015 08:34:13 -0800 Subject: [PATCH] only log to analyzer_err and analyzer_out files in developer mode Reviewed By: jberdine Differential Revision: D2742111 fb-gh-sync-id: 40d5cb3 --- infer/src/backend/inferanalyze.ml | 43 +++++++++++++++++++------------ infer/src/backend/logging.ml | 20 +++++++++----- infer/src/backend/logging.mli | 8 +++--- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/infer/src/backend/inferanalyze.ml b/infer/src/backend/inferanalyze.ml index 64a0aca56..9f5c52053 100644 --- a/infer/src/backend/inferanalyze.ml +++ b/infer/src/backend/inferanalyze.ml @@ -667,9 +667,31 @@ let close_output_file = function | None -> () | Some (fmt, cout) -> close_out cout -let log_dir_name = "log" -let analyzer_out_name = "analyzer_out" -let analyzer_err_name = "analyzer_err" +let setup_logging () = + if !Config.developer_mode then + let log_dir_name = "log" in + let analyzer_out_name = "analyzer_out" in + let analyzer_err_name = "analyzer_err" in + let log_dir = DB.filename_to_string (DB.Results_dir.path_to_filename DB.Results_dir.Abs_root [log_dir_name]) in + DB.create_dir log_dir; + let analyzer_out_file = + if !out_file_cmdline = "" then Filename.concat log_dir analyzer_out_name + else !out_file_cmdline in + let analyzer_err_file = + if !err_file_cmdline = "" then Filename.concat log_dir analyzer_err_name + else !err_file_cmdline in + let analyzer_out_of = open_output_file Logging.set_out_formatter analyzer_out_file in + let analyzer_err_of = open_output_file Logging.set_err_formatter analyzer_err_file in + analyzer_out_of, analyzer_err_of + else None, None + +let teardown_logging analyzer_out_of analyzer_err_of = + if !Config.developer_mode then + begin + L.flush_streams (); + close_output_file analyzer_out_of; + close_output_file analyzer_err_of; + end (** Compute clusters when on-demand is active. Each cluster will contain only the name of the directory for a file. *) @@ -703,16 +725,7 @@ let () = if !allow_specs_cleanup = true && !incremental_mode = ANALYZE_ALL && !cluster_cmdline = None then DB.Results_dir.clean_specs_dir (); - let log_dir = DB.filename_to_string (DB.Results_dir.path_to_filename DB.Results_dir.Abs_root [log_dir_name]) in - DB.create_dir log_dir; - let analyzer_out_file = - if !out_file_cmdline = "" then Filename.concat log_dir analyzer_out_name - else !out_file_cmdline in - let analyzer_err_file = - if !err_file_cmdline = "" then Filename.concat log_dir analyzer_err_name - else !err_file_cmdline in - let analyzer_out_of = open_output_file Logging.set_out_formatter analyzer_out_file in - let analyzer_err_of = open_output_file Logging.set_err_formatter analyzer_err_file in + let analyzer_out_of, analyzer_err_of = setup_logging () in if (!Config.curr_language = Config.C_CPP) then Mleak_buckets.init_buckets !ml_buckets_arg; process_cluster_cmdline_exit (); @@ -744,7 +757,5 @@ let () = let tot_clusters = IList.length clusters in Fork.tot_files := IList.fold_left (fun n cluster -> n + IList.length cluster) 0 clusters; IList.iter (analyze_cluster (ref 0) tot_clusters) clusters; - L.flush_streams (); - close_output_file analyzer_out_of; - close_output_file analyzer_err_of; + teardown_logging analyzer_out_of analyzer_err_of; if !cluster_cmdline = None then L.stdout "Analysis finished in %as@." pp_elapsed_time () diff --git a/infer/src/backend/logging.ml b/infer/src/backend/logging.ml index d6c03fadb..aff0c538d 100644 --- a/infer/src/backend/logging.ml +++ b/infer/src/backend/logging.ml @@ -86,8 +86,11 @@ let set_err_formatter fmt = (** Flush the current streams *) let flush_streams () = - F.fprintf !current_out_formatter "@?"; - F.fprintf !current_err_formatter "@?" + if !Config.developer_mode then + begin + F.fprintf !current_out_formatter "@?"; + F.fprintf !current_err_formatter "@?" + end (** extend the current print log *) let add_print_action pact = @@ -103,21 +106,24 @@ let get_delayed_prints () = !delayed_actions let do_print fmt fmt_string = - F.fprintf fmt fmt_string + if !Config.developer_mode then + F.fprintf fmt fmt_string + else + F.ifprintf fmt fmt_string -(** print on the out stream *) +(** print to the current out stream (note: only prints in developer mode) *) let out fmt_string = do_print !current_out_formatter fmt_string -(** print on the err stream *) +(** print to the current err stream (note: only prints in developer mode) *) let err fmt_string = do_print !current_err_formatter fmt_string -(** print immediately to standard error *) +(** print immediately to standard error (note: only prints in developer mode) *) let stderr fmt_string = do_print F.err_formatter fmt_string -(** print immediately to standard output *) +(** print immediately to standard output (note: only prints in developer mode) *) let stdout fmt_string = do_print F.std_formatter fmt_string diff --git a/infer/src/backend/logging.mli b/infer/src/backend/logging.mli index d145f8314..c80285f51 100644 --- a/infer/src/backend/logging.mli +++ b/infer/src/backend/logging.mli @@ -68,16 +68,16 @@ val get_delayed_prints : unit -> print_action list (** reset the delayed print actions *) val reset_delayed_prints : unit -> unit -(** print to the current out stream *) +(** print to the current out stream (note: only prints in developer mode) *) val out : ('a, Format.formatter, unit) format -> 'a -(** print to the current err stream *) +(** print to the current err stream (note: only prints in developer mode) *) val err : ('a, Format.formatter, unit) format -> 'a -(** print immediately to standard error *) +(** print immediately to standard error (note: only prints in developer mode) *) val stderr : ('a, Format.formatter, unit) format -> 'a -(** print immediately to standard output *) +(** print immediately to standard output (note: only prints in developer mode) *) val stdout : ('a, Format.formatter, unit) format -> 'a (** Get the current out formatter *)