| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Pull a sandwich run's output directory's metrics from traces into a CSV. | 5 """Pull a sandwich run's output directory's metrics from traces into a CSV. |
| 6 | 6 |
| 7 python pull_sandwich_metrics.py -h | 7 python pull_sandwich_metrics.py -h |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import collections | 10 import collections |
| 11 import logging | 11 import logging |
| 12 import os | 12 import os |
| 13 import shutil | 13 import shutil |
| 14 import sys | 14 import sys |
| 15 import tempfile | 15 import tempfile |
| 16 | 16 |
| 17 _SRC_DIR = os.path.abspath(os.path.join( | 17 _SRC_DIR = os.path.abspath(os.path.join( |
| 18 os.path.dirname(__file__), '..', '..', '..')) | 18 os.path.dirname(__file__), '..', '..', '..')) |
| 19 | 19 |
| 20 sys.path.append(os.path.join(_SRC_DIR, 'tools', 'perf')) | 20 sys.path.append(os.path.join(_SRC_DIR, 'tools', 'perf')) |
| 21 from chrome_telemetry_build import chromium_config | 21 from chrome_telemetry_build import chromium_config |
| 22 | 22 |
| 23 sys.path.append(chromium_config.GetTelemetryDir()) | 23 sys.path.append(chromium_config.GetTelemetryDir()) |
| 24 from telemetry.internal.image_processing import video | 24 from telemetry.internal.image_processing import video |
| 25 from telemetry.util import image_util | 25 from telemetry.util import image_util |
| 26 from telemetry.util import rgba_color | 26 from telemetry.util import rgba_color |
| 27 | 27 |
| 28 import loading_trace as loading_trace_module | 28 import loading_trace as loading_trace_module |
| 29 import sandwich_runner |
| 29 import tracing | 30 import tracing |
| 30 | 31 |
| 31 | 32 |
| 32 # List of selected trace event categories when running chrome. | |
| 33 ADDITIONAL_CATEGORIES = ( | |
| 34 'disabled-by-default-memory-infra',) # Used by _GetBrowserDumpEvents() | |
| 35 | |
| 36 CSV_FIELD_NAMES = [ | 33 CSV_FIELD_NAMES = [ |
| 37 'id', | 34 'id', |
| 38 'url', | 35 'url', |
| 39 'total_load', | 36 'total_load', |
| 40 'onload', | 37 'onload', |
| 41 'browser_malloc_avg', | 38 'browser_malloc_avg', |
| 42 'browser_malloc_max', | 39 'browser_malloc_max', |
| 43 'speed_index'] | 40 'speed_index'] |
| 44 | 41 |
| 45 _TRACKED_EVENT_NAMES = set(['requestStart', 'loadEventStart', 'loadEventEnd']) | 42 _TRACKED_EVENT_NAMES = set(['requestStart', 'loadEventStart', 'loadEventEnd']) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 """Pulls all the metrics from a given trace. | 130 """Pulls all the metrics from a given trace. |
| 134 | 131 |
| 135 Args: | 132 Args: |
| 136 loading_trace: loading_trace_module.LoadingTrace. | 133 loading_trace: loading_trace_module.LoadingTrace. |
| 137 | 134 |
| 138 Returns: | 135 Returns: |
| 139 Dictionary with all CSV_FIELD_NAMES's field set (except the 'id'). | 136 Dictionary with all CSV_FIELD_NAMES's field set (except the 'id'). |
| 140 """ | 137 """ |
| 141 assert all( | 138 assert all( |
| 142 cat in loading_trace.tracing_track.Categories() | 139 cat in loading_trace.tracing_track.Categories() |
| 143 for cat in ADDITIONAL_CATEGORIES), ( | 140 for cat in sandwich_runner.ADDITIONAL_CATEGORIES), ( |
| 144 'This trace was not generated with the required set of categories ' | 141 'This trace was not generated with the required set of categories ' |
| 145 'to be processed by this script.') | 142 'to be processed by this script.') |
| 146 browser_dump_events = _GetBrowserDumpEvents(loading_trace.tracing_track) | 143 browser_dump_events = _GetBrowserDumpEvents(loading_trace.tracing_track) |
| 147 web_page_tracked_events = _GetWebPageTrackedEvents( | 144 web_page_tracked_events = _GetWebPageTrackedEvents( |
| 148 loading_trace.tracing_track) | 145 loading_trace.tracing_track) |
| 149 | 146 |
| 150 browser_malloc_sum = 0 | 147 browser_malloc_sum = 0 |
| 151 browser_malloc_max = 0 | 148 browser_malloc_max = 0 |
| 152 for dump_event in browser_dump_events: | 149 for dump_event in browser_dump_events: |
| 153 attr = dump_event.args['dumps']['allocators']['malloc']['attrs']['size'] | 150 attr = dump_event.args['dumps']['allocators']['malloc']['attrs']['size'] |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 assert os.path.isdir(output_directory_path) | 235 assert os.path.isdir(output_directory_path) |
| 239 metrics = [] | 236 metrics = [] |
| 240 for node_name in os.listdir(output_directory_path): | 237 for node_name in os.listdir(output_directory_path): |
| 241 if not os.path.isdir(os.path.join(output_directory_path, node_name)): | 238 if not os.path.isdir(os.path.join(output_directory_path, node_name)): |
| 242 continue | 239 continue |
| 243 try: | 240 try: |
| 244 page_id = int(node_name) | 241 page_id = int(node_name) |
| 245 except ValueError: | 242 except ValueError: |
| 246 continue | 243 continue |
| 247 run_path = os.path.join(output_directory_path, node_name) | 244 run_path = os.path.join(output_directory_path, node_name) |
| 248 trace_path = os.path.join(run_path, 'trace.json') | 245 trace_path = os.path.join(run_path, sandwich_runner.TRACE_FILENAME) |
| 249 if not os.path.isfile(trace_path): | 246 if not os.path.isfile(trace_path): |
| 250 continue | 247 continue |
| 251 logging.info('processing \'%s\'' % trace_path) | 248 logging.info('processing \'%s\'' % trace_path) |
| 252 loading_trace = loading_trace_module.LoadingTrace.FromJsonFile(trace_path) | 249 loading_trace = loading_trace_module.LoadingTrace.FromJsonFile(trace_path) |
| 253 row_metrics = {key: 'unavailable' for key in CSV_FIELD_NAMES} | 250 row_metrics = {key: 'unavailable' for key in CSV_FIELD_NAMES} |
| 254 row_metrics.update(_PullMetricsFromLoadingTrace(loading_trace)) | 251 row_metrics.update(_PullMetricsFromLoadingTrace(loading_trace)) |
| 255 row_metrics['id'] = page_id | 252 row_metrics['id'] = page_id |
| 256 row_metrics['url'] = loading_trace.url | 253 row_metrics['url'] = loading_trace.url |
| 257 video_path = os.path.join(run_path, 'video.mp4') | 254 video_path = os.path.join(run_path, sandwich_runner.VIDEO_FILENAME) |
| 258 if os.path.isfile(video_path): | 255 if os.path.isfile(video_path): |
| 259 logging.info('processing \'%s\'' % video_path) | 256 logging.info('processing \'%s\'' % video_path) |
| 260 completeness_record = _ExtractCompletenessRecordFromVideo(video_path) | 257 completeness_record = _ExtractCompletenessRecordFromVideo(video_path) |
| 261 row_metrics['speed_index'] = ComputeSpeedIndex(completeness_record) | 258 row_metrics['speed_index'] = ComputeSpeedIndex(completeness_record) |
| 262 metrics.append(row_metrics) | 259 metrics.append(row_metrics) |
| 263 assert len(metrics) > 0, ('Looks like \'{}\' was not a sandwich ' + | 260 assert len(metrics) > 0, ('Looks like \'{}\' was not a sandwich ' + |
| 264 'run directory.').format(output_directory_path) | 261 'run directory.').format(output_directory_path) |
| 265 return metrics | 262 return metrics |
| OLD | NEW |