Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
| 2 | # |
| 3 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | # |
| 7 | # pylint: disable=cros-logging-import |
| 8 | |
| 9 | """Script to re-format json result to one with branch_name and build_id""" |
| 10 | from __future__ import print_function |
| 11 | |
| 12 | import argparse |
| 13 | import config |
| 14 | import json |
| 15 | import logging |
| 16 | import os |
| 17 | import subprocess |
| 18 | import sys |
| 19 | |
| 20 | # Turn the logging level to INFO before importing other autotest |
| 21 | # code, to avoid having failed import logging messages confuse the |
| 22 | # test_droid user. |
| 23 | logging.basicConfig(level=logging.INFO) |
| 24 | |
| 25 | |
| 26 | def _parse_arguments_internal(argv): |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 27 | parser = argparse.ArgumentParser(description='Convert result to JSON' |
| 28 | 'format') |
| 29 | parser.add_argument( |
| 30 | '-b', '--bench', help='Generate JSON format file for which benchmark.') |
| 31 | return parser.parse_args(argv) |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 32 | |
| 33 | def fix_json(bench): |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 34 | # Set environment variable for crosperf |
| 35 | os.environ['PYTHONPATH'] = os.path.dirname(config.toolchain_utils) |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 36 | |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 37 | logging.info('Generating Crosperf Report...') |
| 38 | json_path = os.path.join(config.bench_suite_dir, bench + '_refined') |
| 39 | crosperf_cmd = [ |
| 40 | os.path.join(config.toolchain_utils, 'generate_report.py'), '--json', |
| 41 | '-i=' + os.path.join(config.bench_suite_dir, bench + '.json'), |
| 42 | '-o=' + json_path, '-f' |
| 43 | ] |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 44 | |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 45 | # Run crosperf generate_report.py |
| 46 | logging.info('Command: %s', crosperf_cmd) |
| 47 | subprocess.call(crosperf_cmd) |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 48 | |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 49 | json_path += '.json' |
| 50 | with open(json_path) as fout: |
| 51 | objs = json.load(fout) |
| 52 | for obj in objs: |
| 53 | obj['branch_name'] = 'aosp/master' |
| 54 | obj['build_id'] = 0 |
| 55 | with open(json_path, 'w') as fout: |
| 56 | json.dump(objs, fout) |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 57 | |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 58 | logging.info('JSON file fixed successfully!') |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 59 | |
| 60 | def main(argv): |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 61 | arguments = _parse_arguments_internal(argv) |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 62 | |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 63 | bench = arguments.bench |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 64 | |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 65 | fix_json(bench) |
Zhizhou Yang | e598690 | 2017-08-10 17:37:53 -0700 | [diff] [blame] | 66 | |
| 67 | if __name__ == '__main__': |
Zhizhou Yang | 6236292 | 2017-08-30 16:04:36 -0700 | [diff] [blame] | 68 | main(sys.argv[1:]) |