def _test_trace(self, disable=True): try: trace_event.trace_enable(self._log_path) yield finally: if disable: trace_event.trace_disable()
def start_instrumenting(output_file, to_include=(), to_exclude=()): """Enable tracing of all function calls (from specified modules).""" trace_event.trace_enable(output_file) traceFunc = _generate_trace_function(to_include, to_exclude) sys.settrace(traceFunc) threading.settrace(traceFunc)
def _test_trace(self, disable=True, format=None): with tempfile_ext.TemporaryFileName() as filename: self._log_path = filename try: trace_event.trace_enable(self._log_path, format=format) yield finally: if disable: trace_event.trace_disable()
def StartAgentTracing(self, config, timeout): del config # Unused. del timeout # Unused. assert not self.is_tracing, 'Telemetry tracing already running' # Create a temporary file and pass the opened file-like object to # trace_event.trace_enable(); the file will be closed on trace_disable(), # and later passed to a trace data builder in CollectAgentTraceData(). self._trace_file = tempfile.NamedTemporaryFile(delete=False) trace_event.trace_enable( self._trace_file, format=trace_event.JSON_WITH_METADATA) assert self.is_tracing, 'Failed to start Telemetry tracing' return True
def StartAgentTracing(self, config, timeout): self._is_tracing_controllable = self._IsTracingControllable() if not self._is_tracing_controllable: return False tf = tempfile.NamedTemporaryFile(delete=False) self._trace_log = tf.name tf.close() del config # unused del timeout # unused assert not trace_event.trace_is_enabled(), 'Tracing already running.' trace_event.trace_enable(self._trace_log) assert trace_event.trace_is_enabled(), 'Tracing didn\'t enable properly.' return True
def RunTests(self): # Affinitize the tests. if self._test_instance.trace_output: assert not trace_event.trace_is_enabled(), 'Tracing already running.' trace_event.trace_enable(self._test_instance.trace_output + '.json') self._SplitTestsByAffinity() if not self._test_buckets and not self._no_device_tests: raise local_device_test_run.NoTestsError() def run_no_devices_tests(): if not self._no_device_tests: return [] s = HostTestShard(self._env, self._test_instance, self._no_device_tests, retries=3, timeout=self._timeout) return [s.RunTestsOnShard()] def device_shard_helper(shard_id): if device_status.IsBlacklisted( str(self._devices[shard_id]), self._env.blacklist): logging.warning('Device %s is not active. Will not create shard %s.', str(self._devices[shard_id]), shard_id) return None s = DeviceTestShard(self._env, self._test_instance, self._devices[shard_id], shard_id, self._test_buckets[shard_id], retries=self._env.max_tries, timeout=self._timeout) return s.RunTestsOnShard() def run_devices_tests(): if not self._test_buckets: return [] if self._devices is None: self._devices = self._GetAllDevices( self._env.devices, self._test_instance.known_devices_file) device_indices = range(min(len(self._devices), len(self._test_buckets))) shards = parallelizer.Parallelizer(device_indices).pMap( device_shard_helper) return [x for x in shards.pGet(self._timeout) if x is not None] host_test_results, device_test_results = reraiser_thread.RunAsync( [run_no_devices_tests, run_devices_tests]) if self._test_instance.trace_output: assert trace_event.trace_is_enabled(), 'Tracing not running.' trace_event.trace_disable() local_device_test_run.LocalDeviceTestRun._JsonToTrace( self._test_instance.trace_output + '.json', self._test_instance.trace_output) return host_test_results + device_test_results
def _StartAgentTracingImpl(self): """Start tracing for the controller tracing agent. Start tracing for the controller tracing agent. Note that the tracing controller records the "controller side" of the clock sync records, and nothing else. """ if not trace_event.trace_can_enable(): raise RuntimeError, ('Cannot enable trace_event;' ' ensure catapult_base is in PYTHONPATH') controller_log_file = tempfile.NamedTemporaryFile(delete=False) self._log_path = controller_log_file.name controller_log_file.close() trace_event.trace_enable(self._log_path) return True
def StartAgentTracing(self, config, timeout): del config # Unused. del timeout # Unused. assert not self.is_tracing, 'Telemetry tracing already running' # Create a temporary file and pass the opened file-like object to # trace_event.trace_enable(); the file will be closed on trace_disable(). # We keep the name of the file on self._trace_log to read the contents # later in CollectAgentTraceData(). # In contrast with tempfile.NamedTemporaryFile, this avoids an issue on # Windows where the file remained in use "by another process" and raised # an error when trying to clean up the file. fd, self._trace_log = tempfile.mkstemp() trace_event.trace_enable(os.fdopen(fd, 'wb')) assert self.is_tracing, 'Failed to start Telemetry tracing' return True
def StartAgentTracing(self, config, timeout): del timeout # Unused. assert not self.is_tracing, 'Telemetry tracing already running' # Keep Telemetry trace format in accordance with Chrome trace format. if config and config.chrome_trace_config.trace_format == 'proto': trace_format = trace_event.PROTOBUF suffix = '.pb' else: trace_format = trace_event.JSON_WITH_METADATA suffix = '.json' # Create a temporary file and pass the opened file-like object to # trace_event.trace_enable(); the file will be closed on trace_disable(), # and later passed to a trace data builder in CollectAgentTraceData(). self._trace_file = tempfile.NamedTemporaryFile(delete=False, suffix=suffix) trace_event.trace_enable(self._trace_file, format=trace_format) assert self.is_tracing, 'Failed to start Telemetry tracing' return True
def EnableTracing(self): if trace_event.trace_is_enabled(): logging.warning('Tracing is already running.') else: trace_event.trace_enable(self._trace_output)