From 808dd8ee91678317a583d90247afd6e41cf81d98 Mon Sep 17 00:00:00 2001 From: Martino Luca Date: Wed, 29 Aug 2018 04:02:21 -0700 Subject: [PATCH] [Perf] Merge costs report files coming from buck-based analyses Reviewed By: jeremydubreil Differential Revision: D9540204 fbshipit-source-id: 665271a32 --- infer/lib/python/inferlib/bucklib.py | 21 ++++++++++++++++----- infer/lib/python/inferlib/config.py | 1 + infer/src/integration/Driver.ml | 7 +++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/infer/lib/python/inferlib/bucklib.py b/infer/lib/python/inferlib/bucklib.py index a1c124559..4889b63f7 100644 --- a/infer/lib/python/inferlib/bucklib.py +++ b/infer/lib/python/inferlib/bucklib.py @@ -30,6 +30,9 @@ DEFAULT_BUCK_OUT_GEN = os.path.join(DEFAULT_BUCK_OUT, 'gen') INFER_JSON_REPORT = os.path.join(config.BUCK_INFER_OUT, config.JSON_REPORT_FILENAME) +INFER_JSON_COSTS_REPORT = os.path.join(config.BUCK_INFER_OUT, + config.JSON_COSTS_REPORT_FILENAME) + INFER_SCRIPT = """\ #!/usr/bin/env {python_executable} import subprocess @@ -109,9 +112,9 @@ class NotFoundInJar(Exception): pass -def load_json_report(opened_jar): +def load_json_report(opened_jar, path): try: - return json.loads(opened_jar.read(INFER_JSON_REPORT).decode()) + return json.loads(opened_jar.read(path).decode()) except KeyError: raise NotFoundInJar @@ -163,14 +166,18 @@ def collect_results(buck_args, infer_args, start_time, targets): and stores them in in args.infer_out/results.json. """ collected_reports = {} + collected_costs_reports = [] for path in get_output_jars(buck_args, targets): try: with zipfile.ZipFile(path) as jar: - report = load_json_report(jar) + report = load_json_report(jar, INFER_JSON_REPORT) + costs_report = load_json_report(jar, INFER_JSON_COSTS_REPORT) if not infer_args.no_filtering: report = remove_eradicate_conflicts(report) merge_reports(report, collected_reports) + # No need to de-duplicate elements in costs-report, merge all + collected_costs_reports += costs_report except NotFoundInJar: pass except zipfile.BadZipfile: @@ -178,9 +185,13 @@ def collect_results(buck_args, infer_args, start_time, targets): json_report = os.path.join(infer_args.infer_out, config.JSON_REPORT_FILENAME) + json_costs_report = os.path.join(infer_args.infer_out, + config.JSON_COSTS_REPORT_FILENAME) - with open(json_report, 'w') as file_out: - json.dump(collected_reports.values(), file_out) + with open(json_report, 'w') as report_out, \ + open(json_costs_report, 'w') as costs_report_out: + json.dump(collected_reports.values(), report_out) + json.dump(collected_costs_reports, costs_report_out) bugs_out = os.path.join(infer_args.infer_out, config.BUGS_FILENAME) issues.print_and_save_errors(infer_args.infer_out, infer_args.project_root, diff --git a/infer/lib/python/inferlib/config.py b/infer/lib/python/inferlib/config.py index 1efc2f341..f4bd21d29 100644 --- a/infer/lib/python/inferlib/config.py +++ b/infer/lib/python/inferlib/config.py @@ -37,6 +37,7 @@ WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'wrappers') DEFAULT_INFER_OUT = os.path.join(os.getcwd().decode(CODESET), 'infer-out') JSON_REPORT_FILENAME = 'report.json' +JSON_COSTS_REPORT_FILENAME = 'costs-report.json' INFER_BUCK_DEPS_FILENAME = 'infer-deps.txt' BUGS_FILENAME = 'bugs.txt' JAVAC_FILELISTS_FILENAME = 'filelists' diff --git a/infer/src/integration/Driver.ml b/infer/src/integration/Driver.ml index 7d2a151e2..7cd66f2b2 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -105,8 +105,11 @@ let clean_results_dir () = in let suffixes_to_delete = [".txt"; ".csv"; ".json"] in fun name -> - (* Keep the JSON report *) - (not (String.equal (Filename.basename name) Config.report_json)) + (* Keep the JSON report and the JSON costs report *) + (not + (List.exists + ~f:(String.equal (Filename.basename name)) + [Config.report_json; Config.costs_report_json])) && ( List.mem ~equal:String.equal files_to_delete (Filename.basename name) || List.exists ~f:(Filename.check_suffix name) suffixes_to_delete ) in