OLD | NEW |
(Empty) | |
| 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 import itertools |
| 5 |
| 6 from telemetry.core.timeline.model import TimelineModel |
| 7 |
| 8 # All tracing categories not disabled-by-default |
| 9 DEFAULT_TRACE_CATEGORIES = None |
| 10 |
| 11 # Categories for absolute minimum overhead tracing. This contains no |
| 12 # sub-traces of thread tasks, so it's only useful for capturing the |
| 13 # cpu-time spent on threads (as well as needed benchmark traces) |
| 14 MINIMAL_TRACE_CATEGORIES = ("toplevel," |
| 15 "benchmark," |
| 16 "webkit.console," |
| 17 "trace_event_overhead") |
| 18 |
| 19 |
| 20 class TimelineController(object): |
| 21 def __init__(self): |
| 22 super(TimelineController, self).__init__() |
| 23 self.trace_categories = DEFAULT_TRACE_CATEGORIES |
| 24 self._model = None |
| 25 self._renderer_process = None |
| 26 self._actions = [] |
| 27 self._action_ranges = [] |
| 28 |
| 29 def Start(self, page, tab): |
| 30 """Starts gathering timeline data. |
| 31 |
| 32 """ |
| 33 # Resets these member variables incase this object is reused. |
| 34 self._model = None |
| 35 self._renderer_process = None |
| 36 self._actions = [] |
| 37 self._action_ranges = [] |
| 38 if not tab.browser.supports_tracing: |
| 39 raise Exception('Not supported') |
| 40 if self.trace_categories: |
| 41 categories = [self.trace_categories] + \ |
| 42 page.GetSyntheticDelayCategories() |
| 43 else: |
| 44 categories = page.GetSyntheticDelayCategories() |
| 45 tab.browser.StartTracing(','.join(categories)) |
| 46 |
| 47 def Stop(self, tab): |
| 48 timeline_data = tab.browser.StopTracing() |
| 49 self._model = TimelineModel(timeline_data) |
| 50 self._renderer_process = self._model.GetRendererProcessFromTab(tab) |
| 51 self._action_ranges = [ action.GetActiveRangeOnTimeline(self._model) |
| 52 for action in self._actions ] |
| 53 # Make sure no action ranges overlap |
| 54 for combo in itertools.combinations(self._action_ranges, 2): |
| 55 assert not combo[0].Intersects(combo[1]) |
| 56 |
| 57 def AddActionToIncludeInMetric(self, action): |
| 58 self._actions.append(action) |
| 59 |
| 60 @property |
| 61 def model(self): |
| 62 return self._model |
| 63 |
| 64 @property |
| 65 def renderer_process(self): |
| 66 return self._renderer_process |
| 67 |
| 68 @property |
| 69 def action_ranges(self): |
| 70 return self._action_ranges |
OLD | NEW |