ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / tools / perf / measurements / timeline_controller.py
blob2348ec4a89d9f5db5850c3362b8f02b0ab9ff507
1 # Copyright 2014 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 from measurements import smooth_gesture_util
6 from telemetry.core.platform import tracing_category_filter
7 from telemetry.core.platform import tracing_options
8 from telemetry.timeline.model import TimelineModel
9 from telemetry.page.actions import action_runner
10 from telemetry.value import trace
11 from telemetry.web_perf import timeline_interaction_record as tir_module
14 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions'
17 class TimelineController(object):
18 def __init__(self):
19 super(TimelineController, self).__init__()
20 self.trace_categories = None
21 self._model = None
22 self._renderer_process = None
23 self._smooth_records = []
24 self._interaction = None
26 def SetUp(self, page, tab):
27 """Starts gathering timeline data.
29 """
30 # Resets these member variables incase this object is reused.
31 self._model = None
32 self._renderer_process = None
33 if not tab.browser.platform.tracing_controller.IsChromeTracingSupported():
34 raise Exception('Not supported')
35 category_filter = tracing_category_filter.TracingCategoryFilter(
36 filter_string=self.trace_categories)
37 for delay in page.GetSyntheticDelayCategories():
38 category_filter.AddSyntheticDelay(delay)
39 options = tracing_options.TracingOptions()
40 options.enable_chrome_trace = True
41 tab.browser.platform.tracing_controller.Start(options, category_filter)
43 def Start(self, tab):
44 # Start the smooth marker for all actions.
45 runner = action_runner.ActionRunner(tab)
46 self._interaction = runner.BeginInteraction(
47 RUN_SMOOTH_ACTIONS, is_smooth=True)
49 def Stop(self, tab, results):
50 # End the smooth marker for all actions.
51 self._interaction.End()
52 # Stop tracing.
53 timeline_data = tab.browser.platform.tracing_controller.Stop()
54 results.AddValue(trace.TraceValue(
55 results.current_page, timeline_data))
56 self._model = TimelineModel(timeline_data)
57 self._renderer_process = self._model.GetRendererProcessFromTabId(tab.id)
58 renderer_thread = self.model.GetRendererThreadFromTabId(tab.id)
60 run_smooth_actions_record = None
61 self._smooth_records = []
62 for event in renderer_thread.async_slices:
63 if not tir_module.IsTimelineInteractionRecord(event.name):
64 continue
65 r = tir_module.TimelineInteractionRecord.FromAsyncEvent(event)
66 if r.label == RUN_SMOOTH_ACTIONS:
67 assert run_smooth_actions_record is None, (
68 'TimelineController cannot issue more than 1 %s record' %
69 RUN_SMOOTH_ACTIONS)
70 run_smooth_actions_record = r
71 elif r.is_smooth:
72 self._smooth_records.append(
73 smooth_gesture_util.GetAdjustedInteractionIfContainGesture(
74 self.model, r))
76 # If there is no other smooth records, we make measurements on time range
77 # marked by timeline_controller itself.
78 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that
79 # page sets are responsible for issueing the markers themselves.
80 if len(self._smooth_records) == 0 and run_smooth_actions_record:
81 self._smooth_records = [run_smooth_actions_record]
84 def CleanUp(self, tab):
85 if tab.browser.platform.tracing_controller.is_tracing_running:
86 tab.browser.platform.tracing_controller.Stop()
88 @property
89 def model(self):
90 return self._model
92 @property
93 def renderer_process(self):
94 return self._renderer_process
96 @property
97 def smooth_records(self):
98 return self._smooth_records