[Perf] Merge costs report files coming from buck-based analyses

Reviewed By: jeremydubreil

Differential Revision: D9540204

fbshipit-source-id: 665271a32
master
Martino Luca 7 years ago committed by Facebook Github Bot
parent 5894258f43
commit 808dd8ee91

@ -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, INFER_JSON_REPORT = os.path.join(config.BUCK_INFER_OUT,
config.JSON_REPORT_FILENAME) config.JSON_REPORT_FILENAME)
INFER_JSON_COSTS_REPORT = os.path.join(config.BUCK_INFER_OUT,
config.JSON_COSTS_REPORT_FILENAME)
INFER_SCRIPT = """\ INFER_SCRIPT = """\
#!/usr/bin/env {python_executable} #!/usr/bin/env {python_executable}
import subprocess import subprocess
@ -109,9 +112,9 @@ class NotFoundInJar(Exception):
pass pass
def load_json_report(opened_jar): def load_json_report(opened_jar, path):
try: try:
return json.loads(opened_jar.read(INFER_JSON_REPORT).decode()) return json.loads(opened_jar.read(path).decode())
except KeyError: except KeyError:
raise NotFoundInJar 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. and stores them in in args.infer_out/results.json.
""" """
collected_reports = {} collected_reports = {}
collected_costs_reports = []
for path in get_output_jars(buck_args, targets): for path in get_output_jars(buck_args, targets):
try: try:
with zipfile.ZipFile(path) as jar: 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: if not infer_args.no_filtering:
report = remove_eradicate_conflicts(report) report = remove_eradicate_conflicts(report)
merge_reports(report, collected_reports) merge_reports(report, collected_reports)
# No need to de-duplicate elements in costs-report, merge all
collected_costs_reports += costs_report
except NotFoundInJar: except NotFoundInJar:
pass pass
except zipfile.BadZipfile: 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, json_report = os.path.join(infer_args.infer_out,
config.JSON_REPORT_FILENAME) 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: with open(json_report, 'w') as report_out, \
json.dump(collected_reports.values(), file_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) 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, issues.print_and_save_errors(infer_args.infer_out, infer_args.project_root,

@ -37,6 +37,7 @@ WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'wrappers')
DEFAULT_INFER_OUT = os.path.join(os.getcwd().decode(CODESET), 'infer-out') DEFAULT_INFER_OUT = os.path.join(os.getcwd().decode(CODESET), 'infer-out')
JSON_REPORT_FILENAME = 'report.json' JSON_REPORT_FILENAME = 'report.json'
JSON_COSTS_REPORT_FILENAME = 'costs-report.json'
INFER_BUCK_DEPS_FILENAME = 'infer-deps.txt' INFER_BUCK_DEPS_FILENAME = 'infer-deps.txt'
BUGS_FILENAME = 'bugs.txt' BUGS_FILENAME = 'bugs.txt'
JAVAC_FILELISTS_FILENAME = 'filelists' JAVAC_FILELISTS_FILENAME = 'filelists'

@ -105,8 +105,11 @@ let clean_results_dir () =
in in
let suffixes_to_delete = [".txt"; ".csv"; ".json"] in let suffixes_to_delete = [".txt"; ".csv"; ".json"] in
fun name -> fun name ->
(* Keep the JSON report *) (* Keep the JSON report and the JSON costs report *)
(not (String.equal (Filename.basename name) Config.report_json)) (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.mem ~equal:String.equal files_to_delete (Filename.basename name)
|| List.exists ~f:(Filename.check_suffix name) suffixes_to_delete ) || List.exists ~f:(Filename.check_suffix name) suffixes_to_delete )
in in

Loading…
Cancel
Save