1#!/usr/bin/env python 2 3# Copyright 2016 The Chromium Authors. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7'''Tracing agent interface for systrace. 8 9This class represents an agent that captures traces from a particular 10tool (e.g. atrace, ftrace.) 11''' 12 13# Timeout interval constants. 14 15START_STOP_TIMEOUT = 10.0 16GET_RESULTS_TIMEOUT = 30.0 17 18 19class TracingConfig(object): 20 '''Store the tracing configuration options for all Systrace agents. If there 21 are ever any options that are to be shared between all of the agents, those 22 options should go here. 23 ''' 24 def __init__(self): 25 pass 26 27 28class TracingAgent(object): 29 def __init__(self): 30 pass 31 32 def StartAgentTracing(self, config, timeout=None): 33 '''Starts running the trace for this agent. Stops with timeout if 34 not completed within timeout interval. 35 36 Args: 37 config: TracingConfig subclass containing agent-specific options 38 and categories. 39 timeout: Timeout interval in seconds. 40 41 Returns: 42 Boolean value indicating whether or not the trace started successfully. 43 ''' 44 pass 45 46 def StopAgentTracing(self, timeout=None): 47 '''Stops running the trace for this agent and returns immediately. 48 Stops with timeout if not completed within timeout interval. 49 50 Args: 51 timeout: Timeout interval in seconds. 52 53 Returns: 54 Boolean value indicating whether or not the trace started successfully. 55 ''' 56 pass 57 58 def SupportsExplicitClockSync(self): 59 '''Find out if this agent supports recording of clock sync markers. 60 61 Returns: 62 Boolean value indicating whether this agent supports recording 63 of clock sync markers. 64 ''' 65 raise NotImplementedError 66 67 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback): 68 '''Record a clock sync marker for this agent. 69 70 Args: 71 sync_id: Clock sync ID string. 72 did_record_sync_marker_callback: Callback function to call 73 (with arguments: timestamp and sync_id) after the 74 clock sync marker is recorded. 75 ''' 76 raise NotImplementedError 77 78 def GetResults(self, timeout=None): 79 '''Get the completed trace for this agent, stopping with timeout 80 81 Get the completed trace for this agent. Call only after 82 StopAgentTracing is done. This function blocks until the result 83 is collected (note; this may take several seconds). Stops with timeout 84 if not completed within self._options.collection_timeout seconds. 85 86 Args: 87 timeout: Timeout interval in seconds. 88 Returns: 89 Completed trace for this agent. 90 ''' 91 pass 92