NSS: {EC,RSA}PrivateKey shouldn't call crypto::GetPublicNSSKeySlot or GetPrivateNSSKe...
[chromium-blink-merge.git] / tools / perf / metrics / timeline.py
blobb22433a46ad71c6487439de87f6a96be1ecdd174
1 # Copyright 2013 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.
4 import collections
6 from metrics import Metric
7 from telemetry.page import page_measurement
9 TRACING_MODE = 'tracing-mode'
10 TIMELINE_MODE = 'timeline-mode'
12 class TimelineMetric(Metric):
13 def __init__(self, mode):
14 assert mode in (TRACING_MODE, TIMELINE_MODE)
15 super(TimelineMetric, self).__init__()
16 self._mode = mode
17 self._model = None
18 self._thread_for_tab = None
20 def Start(self, page, tab):
21 self._model = None
22 self._thread_for_tab = None
24 if self._mode == TRACING_MODE:
25 if not tab.browser.supports_tracing:
26 raise Exception('Not supported')
27 tab.browser.StartTracing()
28 else:
29 assert self._mode == TIMELINE_MODE
30 tab.StartTimelineRecording()
32 def Stop(self, page, tab):
33 if self._mode == TRACING_MODE:
34 # This creates an async trace event in the render process for tab that
35 # will allow us to find that tab during the AddTracingResultsForTab
36 # function.
37 success = tab.EvaluateJavaScript("""
38 console.time("__loading_measurement_was_here__");
39 console.timeEnd("__loading_measurement_was_here__");
40 console.time.toString().indexOf('[native code]') != -1;
41 """)
42 trace_result = tab.browser.StopTracing()
43 if not success:
44 raise page_measurement.MeasurementFailure(
45 'Page stomped on console.time')
46 self._model = trace_result.AsTimelineModel()
47 events = [s for
48 s in self._model.GetAllEventsOfName(
49 '__loading_measurement_was_here__')
50 if s.parent_slice == None]
51 assert len(events) == 1, 'Expected one marker, got %d' % len(events)
52 # TODO(tonyg): This should be threads_for_tab and report events for both
53 # the starting thread and ending thread.
54 self._thread_for_tab = events[0].start_thread
55 else:
56 tab.StopTimelineRecording()
57 self._model = tab.timeline_model
58 self._thread_for_tab = self._model.GetAllThreads()[0]
60 def AddResults(self, tab, results):
61 assert self._model
63 events = self._thread_for_tab.all_slices
65 events_by_name = collections.defaultdict(list)
66 for e in events:
67 events_by_name[e.name].append(e)
69 for event_name, event_group in events_by_name.iteritems():
70 times = [event.self_time for event in event_group]
71 total = sum(times)
72 biggest_jank = max(times)
73 results.Add(event_name, 'ms', total)
74 results.Add(event_name + '_max', 'ms', biggest_jank)
75 results.Add(event_name + '_avg', 'ms', total / len(times))
77 counters_by_name = self._thread_for_tab.parent.counters
78 for counter_name, counter in counters_by_name.iteritems():
79 total = sum(counter.totals)
80 results.Add(counter_name, 'count', total)
81 results.Add(counter_name + '_avg', 'count', total / len(counter.totals))