diff options
author | Zhizhou Yang <zhizhouy@google.com> | 2017-07-22 01:11:35 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-07-22 01:11:35 +0000 |
commit | ddfea1f7e75062a350bd5a9418562e3b5af5b6e9 (patch) | |
tree | bf139ee25415cecde142e95791edba3803b2452a /android_bench_suite/fix_json.py | |
parent | 3690e025de8daaed03c4acb02d2b054e5c4c0dd5 (diff) | |
parent | 6c551e0d526de7de9d86516614d645cba6f975a6 (diff) | |
download | toolchain-utils-o-mr1-iot-preview-6.tar.gz |
Merge branch 'aosp/mirror-chromium-master' into update_utils am: 4307f4735e am: 18caef1eddandroid-o-mr1-iot-preview-6o-mr1-iot-preview-6
am: 6c551e0d52
Change-Id: I44720cd3cd736bb61f583fb20df1c25ac9323ae0
Diffstat (limited to 'android_bench_suite/fix_json.py')
-rwxr-xr-x | android_bench_suite/fix_json.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/android_bench_suite/fix_json.py b/android_bench_suite/fix_json.py new file mode 100755 index 00000000..cf94dd65 --- /dev/null +++ b/android_bench_suite/fix_json.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python2 +# +# Copyright 2017 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# pylint: disable=cros-logging-import + +"""Script to re-format json result to one with branch_name and build_id""" +from __future__ import print_function + +import argparse +import config +import json +import logging +import os +import subprocess +import sys + +# Turn the logging level to INFO before importing other autotest +# code, to avoid having failed import logging messages confuse the +# test_droid user. +logging.basicConfig(level=logging.INFO) + + +def _parse_arguments_internal(argv): + parser = argparse.ArgumentParser(description='Convert result to JSON' + 'format') + parser.add_argument( + '-b', '--bench', help='Generate JSON format file for which benchmark.') + return parser.parse_args(argv) + +def fix_json(bench): + # Set environment variable for crosperf + os.environ['PYTHONPATH'] = os.path.dirname(config.toolchain_utils) + + logging.info('Generating Crosperf Report...') + json_path = os.path.join(config.bench_suite_dir, bench + '_refined') + crosperf_cmd = [ + os.path.join(config.toolchain_utils, 'generate_report.py'), '--json', + '-i=' + os.path.join(config.bench_suite_dir, bench + '.json'), + '-o=' + json_path, '-f' + ] + + # Run crosperf generate_report.py + logging.info('Command: %s', crosperf_cmd) + subprocess.call(crosperf_cmd) + + json_path += '.json' + with open(json_path) as fout: + objs = json.load(fout) + for obj in objs: + obj['branch_name'] = 'aosp/master' + obj['build_id'] = 0 + with open(json_path, 'w') as fout: + json.dump(objs, fout) + + logging.info('JSON file fixed successfully!') + +def main(argv): + arguments = _parse_arguments_internal(argv) + + bench = arguments.bench + + fix_json(bench) + +if __name__ == '__main__': + main(sys.argv[1:]) |