fix printing number of analysed procs/files

Summary: public
When analysing projects we would not always display the numbers of procs and
files analysed. This fixes it, and also prints the stats before the reports for
readability. This way we also don't need to print "Analysis done" anymore.

Before:

  $ infer -- gcc -c hello.c
  Starting analysis (Infer version git-436690cf022a16313dda8447121a5934529e6e5c)
  Analysis done

  hello.c:5: error: NULL_DEREFERENCE
    pointer s last assigned on line 4 could be null and is dereferenced at line 5, column 3
    3.   void test() {
    4.     int *s = NULL;
    5. >   *s = 42;
    6.   }

After:

  $ infer -- gcc -c hello.c
  Starting analysis (Infer version git-5b7ff3ac10d58e7ffd17c44574ab330ed07cb188)
  Computing dependencies... 100%
  Analyzing 1 cluster. 100%
  Analyzed 1 procedure in 1 file

  Found 1 issue

  hello.c:5: error: NULL_DEREFERENCE
    pointer s last assigned on line 4 could be null and is dereferenced at line 5, column 3
    3.   void test() {
    4.     int *s = NULL;
    5. >   *s = 42;
    6.   }

Also looked at the results on buck and gradle

Reviewed By: cristianoc

Differential Revision: D2636991

fb-gh-sync-id: 32b9a7c
master
Jules Villard 9 years ago committed by facebook-github-bot-1
parent 02b9bec78e
commit 469d1e4902

@ -681,14 +681,13 @@ class Infer:
previous_value = self.stats['int'].get(key, 0) previous_value = self.stats['int'].get(key, 0)
self.stats['int'][key] = previous_value + 1 self.stats['int'][key] = previous_value + 1
def report_errors(self): def create_report(self):
"""Report statistics about the computation and create a CSV file """Report statistics about the computation and create a CSV file
containing the list or errors found during the analysis""" containing the list or errors found during the analysis"""
out_dir = self.args.infer_out out_dir = self.args.infer_out
csv_report = os.path.join(out_dir, utils.CSV_REPORT_FILENAME) csv_report = os.path.join(out_dir, utils.CSV_REPORT_FILENAME)
json_report = os.path.join(out_dir, utils.JSON_REPORT_FILENAME) json_report = os.path.join(out_dir, utils.JSON_REPORT_FILENAME)
bugs_out = os.path.join(out_dir, utils.BUGS_FILENAME)
procs_report = os.path.join(self.args.infer_out, 'procs.csv') procs_report = os.path.join(self.args.infer_out, 'procs.csv')
infer_print_cmd = [utils.get_cmd_in_bin_dir('InferPrint')] infer_print_cmd = [utils.get_cmd_in_bin_dir('InferPrint')]
@ -714,13 +713,9 @@ class Infer:
clean_json(self.args, json_report) clean_json(self.args, json_report)
self.update_stats_with_warnings(csv_report) self.update_stats_with_warnings(csv_report)
if not self.args.buck:
print_errors(csv_report, bugs_out)
return exit_status return exit_status
def save_stats(self): def read_proc_stats(self):
"""Print timing information to infer_out/stats.json"""
proc_stats_path = os.path.join( proc_stats_path = os.path.join(
self.args.infer_out, self.args.infer_out,
utils.PROC_STATS_FILENAME) utils.PROC_STATS_FILENAME)
@ -731,6 +726,8 @@ class Infer:
proc_stats = json.load(proc_stats_file) proc_stats = json.load(proc_stats_file)
self.stats['int'].update(proc_stats) self.stats['int'].update(proc_stats)
def save_stats(self):
"""Print timing information to infer_out/stats.json"""
self.stats['float'] = { self.stats['float'] = {
'capture_time': self.timing.get('capture', 0.0), 'capture_time': self.timing.get('capture', 0.0),
'makefile_generation_time': self.timing.get( 'makefile_generation_time': self.timing.get(
@ -753,12 +750,28 @@ class Infer:
os.remove(self.javac.annotations_out) os.remove(self.javac.annotations_out)
def analyze_and_report(self): def analyze_and_report(self):
should_print_errors = False
if self.args.analyzer not in [COMPILE, CAPTURE]: if self.args.analyzer not in [COMPILE, CAPTURE]:
if self.analyze() == os.EX_OK: if self.analyze() == os.EX_OK:
reporting_start_time = time.time() reporting_start_time = time.time()
self.report_errors() report_status = self.create_report()
elapsed = utils.elapsed_time(reporting_start_time) elapsed = utils.elapsed_time(reporting_start_time)
self.timing['reporting'] = elapsed self.timing['reporting'] = elapsed
self.read_proc_stats()
self.print_analysis_stats()
if report_status == os.EX_OK and not self.args.buck:
csv_report = os.path.join(self.args.infer_out,
utils.CSV_REPORT_FILENAME)
bugs_out = os.path.join(self.args.infer_out,
utils.BUGS_FILENAME)
print_errors(csv_report, bugs_out)
def print_analysis_stats(self):
procs_total = self.stats['int']['procedures']
files_total = self.stats['int']['files']
procs_str = utils.get_plural('procedure', procs_total)
files_str = utils.get_plural('file', files_total)
print('Analyzed %s in %s' % (procs_str, files_str))
def start(self): def start(self):
if self.javac.args.version: if self.javac.args.version:
@ -784,12 +797,6 @@ class Infer:
self.timing['total'] = utils.elapsed_time(start_time) self.timing['total'] = utils.elapsed_time(start_time)
self.save_stats() self.save_stats()
procs_total = self.stats['int']['procedures']
files_total = self.stats['int']['files']
procs_str = utils.get_plural('procedure', procs_total)
files_str = utils.get_plural('file', files_total)
print('\nAnalyzed %s in %s' % (procs_str, files_str))
return self.stats return self.stats
# vim: set sw=4 ts=4 et: # vim: set sw=4 ts=4 et:

@ -48,8 +48,7 @@ let pp_prolog fmt clusters =
clusters; clusters;
F.fprintf fmt "@.@.default: test@.@.all: test@.@."; F.fprintf fmt "@.@.default: test@.@.all: test@.@.";
F.fprintf fmt "test: $(OBJECTS)@."; F.fprintf fmt "test: $(OBJECTS)@.";
if !Config.show_progress_bar then F.fprintf fmt "\techo \"\"@."; if !Config.show_progress_bar then F.fprintf fmt "\techo \"\"@."
F.fprintf fmt "\techo \"Analysis done\"@."
let pp_epilog fmt () = let pp_epilog fmt () =
F.fprintf fmt "@.clean:@.\trm -f $(OBJECTS)@." F.fprintf fmt "@.clean:@.\trm -f $(OBJECTS)@."

Loading…
Cancel
Save