1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 from telemetry
import value
6 from telemetry
.web_perf
.metrics
import timeline_based_metric
8 _PROCESS_CREATION
= 'Startup.BrowserProcessCreation'
9 _MAIN_ENTRY_POINT
= 'Startup.BrowserMainEntryPoint'
11 # A dictionary that maps metric names to a value, which can be either of
13 # 1. A tuple of one event name if the event itself contains reported duration
14 # 2. A tuple of two event names if the value to report is the time difference
15 # between starting these events
17 'messageloop_start_time':
18 ('Startup.BrowserMessageLoopStartTimeFromMainEntry2',),
20 'window_display_time':
21 ('Startup.BrowserWindowDisplay',),
24 ('Startup.BrowserOpenTabs',),
26 'first_non_empty_paint_time':
27 ('Startup.FirstWebContents.NonEmptyPaint2',),
29 'first_main_frame_load_time':
30 ('Startup.FirstWebContents.MainFrameLoad2',),
32 'foreground_tab_load_complete':
33 (_MAIN_ENTRY_POINT
, 'loadEventEnd'),
35 'foreground_tab_request_start':
36 (_MAIN_ENTRY_POINT
, 'requestStart'),
39 _TRACKED_EVENT_NAMES
= set()
40 for i
in _METRICS
.values():
41 _TRACKED_EVENT_NAMES
.add(i
[0])
43 _TRACKED_EVENT_NAMES
.add(i
[1])
46 class StartupTimelineMetric(timeline_based_metric
.TimelineBasedMetric
):
47 """Reports summary stats from important startup events."""
50 super(StartupTimelineMetric
, self
).__init
__()
52 def AddResults(self
, model
, _renderer_thread
, interactions
, results
):
55 def AddWholeTraceResults(self
, model
, results
):
56 browser
= model
.browser_process
61 # Produce a map of events to track.
63 for event
in browser
.parent
.IterAllEvents(
64 event_predicate
=lambda event
: event
.name
in _TRACKED_EVENT_NAMES
):
65 # In case of a begin/end trace event, only track the begin that contain
67 if event
.name
in tracked_events
:
70 tracked_events
[event
.name
] = event
72 # Generate the metric values according to the tracked events.
73 for display_name
, event_names
in _METRICS
.iteritems():
74 if event_names
[0] not in tracked_events
:
78 if len(event_names
) == 1:
79 # The single event contains the duration to report.
80 duration
= tracked_events
[event_names
[0]].duration
82 elif len(event_names
) == 2:
83 # The duration is defined as the difference between two event starts.
84 if event_names
[1] not in tracked_events
:
87 duration
= (tracked_events
[event_names
[1]].start
-
88 tracked_events
[event_names
[0]].start
)
90 results
.AddValue(value
.scalar
.ScalarValue(
91 page
=results
.current_page
,
95 improvement_direction
=value
.improvement_direction
.DOWN
))