| Index: tools/telemetry/telemetry/web_perf/metrics/startup.py
|
| diff --git a/tools/telemetry/telemetry/web_perf/metrics/startup.py b/tools/telemetry/telemetry/web_perf/metrics/startup.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1c9d638eaa3db1cc646eb5785ae8034e99196522
|
| --- /dev/null
|
| +++ b/tools/telemetry/telemetry/web_perf/metrics/startup.py
|
| @@ -0,0 +1,105 @@
|
| +# Copyright 2015 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +from telemetry import value
|
| +from telemetry.web_perf.metrics import timeline_based_metric
|
| +
|
| +_PROCESS_CREATION = 'Startup.BrowserProcessCreation'
|
| +_MAIN_ENTRY_POINT = 'Startup.BrowserMainEntryPoint'
|
| +
|
| +# Map of all startup metric's values's to the trace events.
|
| +_METRICS = {
|
| + # "display_name":
|
| + # ("starting mark event's name", "ending mark event's name"),
|
| + #OR ("begin/end event's name"),
|
| +
|
| + 'messageloop_start_time':
|
| + ('Startup.BrowserMessageLoopStartTimeFromMainEntry',),
|
| +
|
| + 'window_display_time':
|
| + ('Startup.BrowserWindowDisplay',),
|
| +
|
| + 'open_tabs_time':
|
| + ('Startup.BrowserOpenTabs',),
|
| +
|
| + 'first_non_empty_paint_time':
|
| + ('Startup.FirstWebContents.NonEmptyPaint2',),
|
| +
|
| + 'first_main_frame_load_time':
|
| + ('Startup.FirstWebContents.MainFrameLoad2',),
|
| +
|
| + 'foreground_tab_load_complete':
|
| + (_MAIN_ENTRY_POINT, 'loadEventEnd'),
|
| +
|
| + #TODO(gabadie): once 552472 fixed, enable this code
|
| + # 'foreground_tab_request_start':
|
| + # (_MAIN_ENTRY_POINT, 'requestStart'),
|
| +}
|
| +
|
| +# List of all event names to track.
|
| +_TRACKED_EVENT_NAMES = set()
|
| +for i in _METRICS.values():
|
| + _TRACKED_EVENT_NAMES.add(i[0])
|
| + if len(i) == 2:
|
| + _TRACKED_EVENT_NAMES.add(i[1])
|
| +
|
| +
|
| +class StartupTimelineMetric(timeline_based_metric.TimelineBasedMetric):
|
| + """Reports summary stats from important startup events.
|
| +
|
| + At startup time, there are several events within it that are interesting to
|
| + track Chrome's performance.
|
| + """
|
| +
|
| + def __init__(self):
|
| + super(StartupTimelineMetric, self).__init__()
|
| +
|
| + def AddResults(self, model, _renderer_thread, interactions, results):
|
| + pass
|
| +
|
| + def AddWholeTraceResults(self, model, results):
|
| + browser = model.browser_process
|
| +
|
| + if not browser:
|
| + return
|
| +
|
| + # Maps all the events we are interested in.
|
| + tracked_events = {}
|
| + for event in browser.parent.IterAllEvents(
|
| + event_predicate=lambda event: event.name in _TRACKED_EVENT_NAMES):
|
| + # In case of a begin/end trace event, only track the begin that contain
|
| + # the duration.
|
| + if event.name in tracked_events:
|
| + continue
|
| +
|
| + tracked_events[event.name] = event
|
| +
|
| + # Generates the metric values according to the tracked events
|
| + for display_name, event_names in _METRICS.iteritems():
|
| + if event_names[0] not in tracked_events:
|
| + continue
|
| +
|
| + duration = None
|
| + if len(event_names) == 1:
|
| + # If len(event_names) == 1, then it means we are using a begin/end
|
| + # trace event, therefor we directly fetch the duration of this event.
|
| + duration = tracked_events[event_names[0]].duration
|
| +
|
| + elif len(event_names) == 2:
|
| + # If len(event_names) == 1, then it means we are using two instant/mark
|
| + # trace events, therefor we manually diff the timestamps.
|
| + if event_names[1] not in tracked_events:
|
| + continue
|
| +
|
| + duration = (tracked_events[event_names[1]].start -
|
| + tracked_events[event_names[0]].start)
|
| +
|
| + assert duration != None, 'something is wrong in _METRICS'
|
| +
|
| + results.AddValue(value.scalar.ScalarValue(
|
| + page=results.current_page,
|
| + name=display_name,
|
| + units='ms',
|
| + value=duration,
|
| + improvement_direction=value.improvement_direction.DOWN))
|
|
|