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