Aggregate stats info emitted during analysis

Summary:
Run `InferStatsAggregator` at the end of the execution of `infer` top-level, and store
results on `infer-out/(frontend|backend|reporting)_stats/aggregated_stats.json`
Not ready yet for buck targets analyzed without the use of an `#infer*` flavor.

Reviewed By: jvillard

Differential Revision: D3365504

fbshipit-source-id: 98b2eb3
master
Martino Luca 9 years ago committed by Facebook Github Bot 1
parent 6d37b5ee6d
commit c39f3b0768

@ -19,6 +19,7 @@ from inferlib import analyze, config, utils
from inferlib.capture import make
CAPTURE_PACKAGE = 'capture'
TOP_LEVEL_ENVVAR = 'TOP_LEVEL_INFER_INSTANCE_ALREADY_RUNNING'
# token that identifies the end of the options for infer and the beginning
# of the compilation command
@ -99,6 +100,12 @@ def create_argparser(parents=[]):
def main():
toplevel_envvar_value = os.environ.get(TOP_LEVEL_ENVVAR, None)
is_toplevel_instance = False
if toplevel_envvar_value is None:
os.environ[TOP_LEVEL_ENVVAR] = '1'
is_toplevel_instance = True
to_parse, cmd = split_args_to_parse()
# get the module name (if any), then load it
capture_module_name = os.path.basename(cmd[0]) if len(cmd) > 0 else None
@ -179,6 +186,18 @@ def main():
analysis.analyze_and_report()
analysis.save_stats()
if is_toplevel_instance is True:
buck_out_for_stats_aggregator = None
if (mod_name == 'buck' and
os.path.isfile(
os.path.join(args.infer_out,
config.INFER_BUCK_DEPS_FILENAME))):
buck_out_for_stats_aggregator = 'buck-out'
logging.info('Aggregating stats')
output = utils.run_infer_stats_aggregator(
args.infer_out, buck_out_for_stats_aggregator)
logging.info(output)
if args.fail_on_bug:
bugs_filename = os.path.join(args.infer_out,
config.JSON_REPORT_FILENAME)

@ -129,6 +129,22 @@ def infer_key(analyzer):
return os.pathsep.join([analyzer, infer_version()])
def run_infer_stats_aggregator(infer_out, buck_out=None):
buck_out_args = []
if buck_out is not None:
buck_out_args = ['--buck-out', buck_out]
try:
cmd = get_cmd_in_bin_dir('InferStatsAggregator')
return subprocess.check_output(
[cmd, '--results-dir', infer_out] + buck_out_args,
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as exc:
output = 'Error while aggregating stats ({ec}): {output}'\
.format(ec=exc.returncode, output=exc.output)
stderr(output)
return output
def vcs_branch(dir='.'):
cwd = os.getcwd()
devnull = open(os.devnull, 'w')

Loading…
Cancel
Save