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.internal.platform import tracing_agent
6
7
8class TracingController(tracing_agent.TracingAgent):
9
10  def __init__(self, tracing_controller_backend):
11    """Provides control of the tracing systems supported by telemetry."""
12    super(TracingController, self).__init__(
13        tracing_controller_backend._platform_backend)
14    self._tracing_controller_backend = tracing_controller_backend
15
16  def StartTracing(self, tracing_config, timeout=10):
17    """Starts tracing.
18
19    tracing config contains both tracing options and category filters.
20
21    trace_options specifies which tracing systems to activate. Category filter
22    allows fine-tuning of the data that are collected by the selected tracing
23    systems.
24
25    Some tracers are process-specific, e.g. chrome tracing, but are not
26    guaranteed to be supported. In order to support tracing of these kinds of
27    tracers, Start will succeed *always*, even if the tracing systems you have
28    requested are not supported.
29
30    If you absolutely require a particular tracer to exist, then check
31    for its support after you have started the process in question. Or, have
32    your code fail gracefully when the data you require is not present in the
33    resulting trace.
34    """
35    self._tracing_controller_backend.StartTracing(tracing_config, timeout)
36
37  def StopTracing(self):
38    """Stops tracing and returns a TraceValue."""
39    return self._tracing_controller_backend.StopTracing()
40
41  def FlushTracing(self):
42    """Flush tracing buffer and continue tracing.
43
44    Warning: This method is a temporary hack to enable multi-tab benchmarks
45    (see https://goo.gl/8Gjstr). Please contact Telemetry owners before using
46    it.
47    """
48    self._tracing_controller_backend.FlushTracing()
49
50  @property
51  def is_tracing_running(self):
52    return self._tracing_controller_backend.is_tracing_running
53
54  def IsChromeTracingSupported(self):
55    """Returns whether chrome tracing is supported."""
56    return self._tracing_controller_backend.IsChromeTracingSupported()
57
58  def StartAgentTracing(self, config, timeout=10):
59    """ Starts agent tracing for tracing controller"""
60    return self._tracing_controller_backend.StartAgentTracing(config, timeout)
61
62  def StopAgentTracing(self, trace_data_builder):
63    """ Stops agent tracing for tracing controller. """
64    return self._tracing_controller_backend.StopAgentTracing(trace_data_builder)
65
66  def SupportsExplicitClockSync(self):
67    return self._tracing_controller_backend.SupportsExplicitClockSync()
68
69  def RecordClockSyncMarker(self, sync_id,
70                            record_controller_clocksync_marker_callback):
71    return self._tracing_controller_backend.RecordClockSyncMarker(
72        sync_id, record_controller_clocksync_marker_callback)
73
74  def ClearStateIfNeeded(self):
75    """Clear tracing state if needed."""
76    self._tracing_controller_backend.ClearStateIfNeeded()
77