blob: 4e54d313840d56e2deb5d54e886166a6000cf855 [file] [log] [blame]
Zhizhou Yange5986902017-08-10 17:37:53 -07001#!/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"""
10from __future__ import print_function
11
12import argparse
13import config
14import json
15import logging
16import os
17import subprocess
18import 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.
23logging.basicConfig(level=logging.INFO)
24
25
26def _parse_arguments_internal(argv):
Zhizhou Yang62362922017-08-30 16:04:36 -070027 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 Yange5986902017-08-10 17:37:53 -070032
33def fix_json(bench):
Zhizhou Yang62362922017-08-30 16:04:36 -070034 # Set environment variable for crosperf
35 os.environ['PYTHONPATH'] = os.path.dirname(config.toolchain_utils)
Zhizhou Yange5986902017-08-10 17:37:53 -070036
Zhizhou Yang62362922017-08-30 16:04:36 -070037 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 Yange5986902017-08-10 17:37:53 -070044
Zhizhou Yang62362922017-08-30 16:04:36 -070045 # Run crosperf generate_report.py
46 logging.info('Command: %s', crosperf_cmd)
47 subprocess.call(crosperf_cmd)
Zhizhou Yange5986902017-08-10 17:37:53 -070048
Zhizhou Yang62362922017-08-30 16:04:36 -070049 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 Yange5986902017-08-10 17:37:53 -070057
Zhizhou Yang62362922017-08-30 16:04:36 -070058 logging.info('JSON file fixed successfully!')
Zhizhou Yange5986902017-08-10 17:37:53 -070059
60def main(argv):
Zhizhou Yang62362922017-08-30 16:04:36 -070061 arguments = _parse_arguments_internal(argv)
Zhizhou Yange5986902017-08-10 17:37:53 -070062
Zhizhou Yang62362922017-08-30 16:04:36 -070063 bench = arguments.bench
Zhizhou Yange5986902017-08-10 17:37:53 -070064
Zhizhou Yang62362922017-08-30 16:04:36 -070065 fix_json(bench)
Zhizhou Yange5986902017-08-10 17:37:53 -070066
67if __name__ == '__main__':
Zhizhou Yang62362922017-08-30 16:04:36 -070068 main(sys.argv[1:])