| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """A tool that runs a perf test and uploads the resulting data to the | 6 """A tool that runs a perf test and uploads the resulting data to the |
| 7 performance dashboard. | 7 performance dashboard. |
| 8 | 8 |
| 9 By default uploads to a local testing dashboard assumed to be running on the | 9 By default uploads to a local testing dashboard assumed to be running on the |
| 10 host. To run such server, check out Catapult and follow instructions at | 10 host. To run such server, check out Catapult and follow instructions at |
| 11 https://github.com/catapult-project/catapult/blob/master/dashboard/README.md . | 11 https://github.com/catapult-project/catapult/blob/master/dashboard/README.md . |
| 12 """ | 12 """ |
| 13 | 13 |
| 14 # TODO(yzshen): The following are missing currently: | 14 # TODO(yzshen): The following are missing currently: |
| 15 # (1) CL range on the dashboard; | 15 # (1) CL range on the dashboard; |
| 16 # (2) improvement direction on the dashboard; | 16 # (2) improvement direction on the dashboard; |
| 17 # (3) a link from the build step pointing to the dashboard page. | 17 # (3) a link from the build step pointing to the dashboard page. |
| 18 | 18 |
| 19 import argparse | 19 import argparse |
| 20 import subprocess | 20 import subprocess |
| 21 import sys | 21 import sys |
| 22 import re | 22 import re |
| 23 | 23 |
| 24 from mopy.version import Version | |
| 25 | |
| 26 import devtools | 24 import devtools |
| 27 devtools.add_lib_to_path() | 25 devtools.add_lib_to_path() |
| 28 from devtoolslib import perf_dashboard | 26 from devtoolslib import perf_dashboard |
| 29 | 27 |
| 30 _PERF_LINE_FORMAT = r"""^\s*([^\s/]+) # chart name | 28 _PERF_LINE_FORMAT = r"""^\s*([^\s/]+) # chart name |
| 31 (/([^\s/]+))? # trace name (optional, separated with | 29 (/([^\s/]+))? # trace name (optional, separated with |
| 32 # the chart name by a '/') | 30 # the chart name by a '/') |
| 33 \s+(\S+) # value | 31 \s+(\S+) # value |
| 34 \s+(\S+) # units | 32 \s+(\S+) # units |
| 35 \s*$""" | 33 \s*$""" |
| 36 | 34 |
| 37 _PERF_LINE_REGEX = re.compile(_PERF_LINE_FORMAT, re.VERBOSE) | 35 _PERF_LINE_REGEX = re.compile(_PERF_LINE_FORMAT, re.VERBOSE) |
| 38 | 36 |
| 39 | 37 |
| 40 def _GetCurrentCommitCount(): | |
| 41 return subprocess.check_output( | |
| 42 ["git", "rev-list", "HEAD", "--count"]).strip() | |
| 43 | |
| 44 | |
| 45 def _ConvertPerfDataToChartFormat(perf_data, test_name): | 38 def _ConvertPerfDataToChartFormat(perf_data, test_name): |
| 46 """Converts the perf data produced by a perf test to the "chart_data" format | 39 """Converts the perf data produced by a perf test to the "chart_data" format |
| 47 accepted by the performance dashboard, see: | 40 accepted by the performance dashboard, see: |
| 48 http://www.chromium.org/developers/speed-infra/performance-dashboard/sending-d
ata-to-the-performance-dashboard. | 41 http://www.chromium.org/developers/speed-infra/performance-dashboard/sending-d
ata-to-the-performance-dashboard. |
| 49 | 42 |
| 50 Returns: | 43 Returns: |
| 51 A dictionary that (after being converted to JSON) conforms to the server | 44 A dictionary that (after being converted to JSON) conforms to the server |
| 52 format. | 45 format. |
| 53 """ | 46 """ |
| 54 charts = {} | 47 charts = {} |
| (...skipping 29 matching lines...) Expand all Loading... |
| 84 "--perf-data-path", | 77 "--perf-data-path", |
| 85 help="The path to the perf data that the perf test generates.") | 78 help="The path to the perf data that the perf test generates.") |
| 86 parser.add_argument("command", nargs=argparse.REMAINDER) | 79 parser.add_argument("command", nargs=argparse.REMAINDER) |
| 87 args = parser.parse_args() | 80 args = parser.parse_args() |
| 88 | 81 |
| 89 subprocess.check_call(args.command) | 82 subprocess.check_call(args.command) |
| 90 | 83 |
| 91 if not args.upload: | 84 if not args.upload: |
| 92 return 0 | 85 return 0 |
| 93 | 86 |
| 94 if args.master_name is None or \ | 87 if not args.test_name or not args.perf_data_path: |
| 95 args.bot_name is None or \ | 88 print ("Can't upload perf data to the dashboard because not all of the " |
| 96 args.test_name is None or \ | 89 "following values are specified: test-name, perf-data-path.") |
| 97 args.builder_name is None or \ | |
| 98 args.build_number is None or \ | |
| 99 args.perf_data_path is None: | |
| 100 print "Can't upload perf data to the dashboard because not all of the " \ | |
| 101 "following values are specified: master-name, perf-id, test-name, " \ | |
| 102 "builder-name, build-number, perf-data-path." | |
| 103 return 1 | 90 return 1 |
| 104 | 91 |
| 105 revision = Version().version | |
| 106 point_id = _GetCurrentCommitCount() | |
| 107 with open(args.perf_data_path, "r") as perf_data: | 92 with open(args.perf_data_path, "r") as perf_data: |
| 108 chart_data = _ConvertPerfDataToChartFormat(perf_data, args.test_name) | 93 chart_data = _ConvertPerfDataToChartFormat(perf_data, args.test_name) |
| 109 | 94 |
| 110 result = perf_dashboard.upload_chart_data( | 95 result = perf_dashboard.upload_chart_data( |
| 111 args.master_name, args.bot_name, args.test_name, args.builder_name, | 96 args.master_name, args.bot_name, args.test_name, args.builder_name, |
| 112 args.build_number, revision, chart_data, point_id, args.server_url, | 97 args.build_number, chart_data, args.server_url, |
| 113 args.dry_run) | 98 args.dry_run) |
| 114 | 99 |
| 115 return 0 if result else 1 | 100 return 0 if result else 1 |
| 116 | 101 |
| 117 | 102 |
| 118 if __name__ == '__main__': | 103 if __name__ == '__main__': |
| 119 sys.exit(main()) | 104 sys.exit(main()) |
| OLD | NEW |