• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5from telemetry.core.platform import tracing_category_filter
6from telemetry.core.platform import tracing_options
7
8
9class TracingControllerBackend(object):
10  def __init__(self, platform_backend):
11    self._platform_backend = platform_backend
12    self._current_trace_options = None
13    self._current_category_filter = None
14
15  def Start(self, trace_options, category_filter, timeout):
16    if self.is_tracing_running:
17      return False
18
19    assert isinstance(category_filter,
20                      tracing_category_filter.TracingCategoryFilter)
21    assert isinstance(trace_options,
22                      tracing_options.TracingOptions)
23
24    num_running_browser_backends = len(self.running_browser_backends)
25    if num_running_browser_backends != 1:
26      # Note: it is possible to implement tracing for both the case of 0 and >1.
27      # For >1, we just need to merge the trace files at StopTracing.
28      #
29      # For 0, we want to modify chrome's trace-startup to support leaving
30      # tracing on indefinitely. Then have the backend notify the platform
31      # and the tracing controller that it is starting a browser, have
32      # the controller add in the trace-startup command, and then when we get
33      # the Stop message or the DidStopBrowser(), issue the stop tracing command
34      # on the right backend.
35      raise NotImplementedError(
36          'Start tracing does not support the case of %i running browser '
37          'instances' % num_running_browser_backends)
38
39    self._current_trace_options = trace_options
40    self._current_category_filter = category_filter
41
42    if trace_options.enable_chrome_trace:
43      browser_backend = self.running_browser_backends[0]
44      browser_backend.StartTracing(
45          trace_options, category_filter.filter_string, timeout)
46
47  def Stop(self):
48    if not self.is_tracing_running:
49      raise Exception('Not tracing')
50    if len(self.running_browser_backends) != 1:
51      raise NotImplementedError()
52
53    result = None
54    if self._current_trace_options.enable_chrome_trace:
55      browser_backend = self.running_browser_backends[0]
56      result = browser_backend.StopTracing()
57
58    self._current_trace_options = None
59    self._current_category_filter = None
60    return result
61
62  def IsChromeTracingSupported(self, browser):
63    browser_backend = self._platform_backend.GetBackendForBrowser(browser)
64    return browser_backend.supports_tracing
65
66  @property
67  def is_tracing_running(self):
68    return self._current_trace_options != None
69
70  @property
71  def running_browser_backends(self):
72    return self._platform_backend.running_browser_backends
73
74  def DidStartBrowser(self, browser, browser_backend):
75    pass
76
77  def WillCloseBrowser(self, browser, browser_backend):
78    pass
79