| 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 CATEGORIES = [ | |
| 34 # Need blink network trace events for prefetch_view.PrefetchSimulationView | |
| 35 'blink.net', | |
| 36 | |
| 37 # Need to get mark trace events for _GetWebPageTrackedEvents() | |
| 38 'blink.user_timing', | |
| 39 | |
| 40 # Need to memory dump trace event for _GetBrowserDumpEvents() | |
| 41 'disabled-by-default-memory-infra'] | |
| 42 | |
| 43 CSV_FIELD_NAMES = [ | 33 CSV_FIELD_NAMES = [ |
| 44 'id', | 34 'id', |
| 45 'url', | 35 'url', |
| 46 'total_load', | 36 'total_load', |
| 47 'onload', | 37 'onload', |
| 48 'browser_malloc_avg', | 38 'browser_malloc_avg', |
| 49 'browser_malloc_max', | 39 'browser_malloc_max', |
| 50 'speed_index'] | 40 'speed_index'] |
| 51 | 41 |
| 52 _TRACKED_EVENT_NAMES = set(['requestStart', 'loadEventStart', 'loadEventEnd']) | 42 _TRACKED_EVENT_NAMES = set(['requestStart', 'loadEventStart', 'loadEventEnd']) |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 assert os.path.isdir(output_directory_path) | 230 assert os.path.isdir(output_directory_path) |
| 241 metrics = [] | 231 metrics = [] |
| 242 for node_name in os.listdir(output_directory_path): | 232 for node_name in os.listdir(output_directory_path): |
| 243 if not os.path.isdir(os.path.join(output_directory_path, node_name)): | 233 if not os.path.isdir(os.path.join(output_directory_path, node_name)): |
| 244 continue | 234 continue |
| 245 try: | 235 try: |
| 246 page_id = int(node_name) | 236 page_id = int(node_name) |
| 247 except ValueError: | 237 except ValueError: |
| 248 continue | 238 continue |
| 249 run_path = os.path.join(output_directory_path, node_name) | 239 run_path = os.path.join(output_directory_path, node_name) |
| 250 trace_path = os.path.join(run_path, 'trace.json') | 240 trace_path = os.path.join(run_path, sandwich_runner.TRACE_FILENAME) |
| 251 if not os.path.isfile(trace_path): | 241 if not os.path.isfile(trace_path): |
| 252 continue | 242 continue |
| 253 logging.info('processing \'%s\'' % trace_path) | 243 logging.info('processing \'%s\'' % trace_path) |
| 254 loading_trace = loading_trace_module.LoadingTrace.FromJsonFile(trace_path) | 244 loading_trace = loading_trace_module.LoadingTrace.FromJsonFile(trace_path) |
| 255 row_metrics = {key: 'unavailable' for key in CSV_FIELD_NAMES} | 245 row_metrics = {key: 'unavailable' for key in CSV_FIELD_NAMES} |
| 256 row_metrics.update(_PullMetricsFromLoadingTrace(loading_trace)) | 246 row_metrics.update(_PullMetricsFromLoadingTrace(loading_trace)) |
| 257 row_metrics['id'] = page_id | 247 row_metrics['id'] = page_id |
| 258 row_metrics['url'] = loading_trace.url | 248 row_metrics['url'] = loading_trace.url |
| 259 video_path = os.path.join(run_path, 'video.mp4') | 249 video_path = os.path.join(run_path, sandwich_runner.VIDEO_FILENAME) |
| 260 if os.path.isfile(video_path): | 250 if os.path.isfile(video_path): |
| 261 logging.info('processing \'%s\'' % video_path) | 251 logging.info('processing \'%s\'' % video_path) |
| 262 completeness_record = _ExtractCompletenessRecordFromVideo(video_path) | 252 completeness_record = _ExtractCompletenessRecordFromVideo(video_path) |
| 263 row_metrics['speed_index'] = ComputeSpeedIndex(completeness_record) | 253 row_metrics['speed_index'] = ComputeSpeedIndex(completeness_record) |
| 264 metrics.append(row_metrics) | 254 metrics.append(row_metrics) |
| 265 assert len(metrics) > 0, ('Looks like \'{}\' was not a sandwich ' + | 255 assert len(metrics) > 0, ('Looks like \'{}\' was not a sandwich ' + |
| 266 'run directory.').format(output_directory_path) | 256 'run directory.').format(output_directory_path) |
| 267 return metrics | 257 return metrics |
| OLD | NEW |