def _test_trace(self, disable=True): try: trace_event.trace_enable(self._log_path) yield finally: if disable: trace_event.trace_disable()
def testDisable(self): with self._test_trace(disable=False): with open(self._log_path, 'r') as f: self.assertTrue(trace_event.trace_is_enabled()) trace_event.trace_disable() self.assertEquals(len(json.loads(f.read() + ']')), 1) self.assertFalse(trace_event.trace_is_enabled())
def StopAgentTracing(self): if not self._is_tracing_controllable: return assert trace_event.trace_is_enabled(), 'Tracing not running' trace_event.trace_disable() assert not trace_event.trace_is_enabled( ), 'Tracing didnt disable properly.'
def DisableTracing(self): if not trace_event.trace_is_enabled(): logging.warning('Tracing is not running.') else: trace_event.trace_disable() self._JsonToTrace(self._trace_output + '.json', self._trace_output)
def testAddMetadata(self): with self._test_trace(format=trace_event.JSON_WITH_METADATA): trace_event.trace_add_benchmark_metadata( benchmark_start_time_us=1000, story_run_time_us=2000, benchmark_name='benchmark', benchmark_description='desc', story_name='story', story_tags=['tag1', 'tag2'], story_run_index=0, ) trace_event.trace_disable() with open(self._log_path, 'r') as f: log_output = json.load(f) self.assertEquals(len(log_output), 2) telemetry_metadata = log_output['metadata']['telemetry'] self.assertEquals(len(telemetry_metadata), 7) self.assertEquals(telemetry_metadata['benchmarkStart'], 1) self.assertEquals(telemetry_metadata['traceStart'], 2) self.assertEquals(telemetry_metadata['benchmarks'], ['benchmark']) self.assertEquals(telemetry_metadata['benchmarkDescriptions'], ['desc']) self.assertEquals(telemetry_metadata['stories'], ['story']) self.assertEquals(telemetry_metadata['storyTags'], ['tag1', 'tag2']) self.assertEquals(telemetry_metadata['storysetRepeats'], [0])
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 StopAgentTracing(self, timeout=None): """Stops tracing for the controller tracing agent. """ # pylint: disable=no-self-use # This function doesn't use self, but making it a member function # for consistency with the other TracingAgents trace_event.trace_disable() return True
def testAddMetadata(self): with self._test_trace(format=trace_event.JSON_WITH_METADATA): trace_event.trace_add_metadata({'version': 1}) trace_event.trace_disable() with open(self._log_path, 'r') as f: log_output = json.load(f) self.assertEquals(len(log_output), 2) self.assertEquals(log_output['metadata']['version'], 1)
def testFormatJsonWithMetadata(self): with self._test_trace(format=trace_event.JSON_WITH_METADATA): trace_event.trace_disable() with open(self._log_path, 'r') as f: log_output = json.load(f) self.assertEquals(len(log_output), 2) events = log_output['traceEvents'] self.assertEquals(len(events), 1) self.assertEquals(events[0]['ph'], 'M')
def testSetClockSnapshotProtobuf(self): trace_event.trace_set_clock_snapshot( telemetry_ts=1234.5678, boottime_ts=8765.4321, ) with self._test_trace(format=trace_event.PROTOBUF): trace_event.trace_disable() with open(self._log_path, 'r') as f: self.assertGreater(len(f.read()), 0)
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 testDisable(self): _old_multiprocessing_process = multiprocessing.Process with self._test_trace(disable=False): with open(self._log_path, 'r') as f: self.assertTrue(trace_event.trace_is_enabled()) self.assertEqual(multiprocessing.Process, multiprocessing_shim.ProcessShim) trace_event.trace_disable() self.assertEqual(multiprocessing.Process, _old_multiprocessing_process) self.assertEquals(len(json.loads(f.read() + ']')), 1) self.assertFalse(trace_event.trace_is_enabled())
def testAddMetadataProtobuf(self): with self._test_trace(format=trace_event.PROTOBUF): trace_event.trace_add_benchmark_metadata( benchmark_start_time_us=1000, story_run_time_us=2000, benchmark_name='benchmark', benchmark_description='desc', story_name='story', story_tags=['tag1', 'tag2'], story_run_index=0, ) trace_event.trace_disable() with open(self._log_path, 'r') as f: self.assertGreater(len(f.read()), 0)
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 StopAgentTracing(self, trace_data_builder): if not self._is_tracing_controllable: return assert trace_event.trace_is_enabled(), 'Tracing not running' trace_event.trace_disable() assert not trace_event.trace_is_enabled(), 'Tracing didnt disable properly.' with open(self._trace_log, 'r') as fp: data = ast.literal_eval(fp.read() + ']') trace_data_builder.AddEventsTo(trace_data_module.TELEMETRY_PART, data) try: os.remove(self._trace_log) self._trace_log = None except OSError: logging.exception('Error when deleting %s, will try again at exit.', self._trace_log) def DeleteAtExit(path): os.remove(path) atexit.register(DeleteAtExit, self._trace_log) self._trace_log = None
def StopAgentTracing(self): assert self.is_tracing, 'Telemetry tracing is not running' trace_event.trace_disable() assert not self.is_tracing, 'Failed to stop Telemetry tracing'
def bad_child(): trace_event.trace_disable()
def StopAgentTracing(self): if not self._is_tracing_controllable: return assert trace_event.trace_is_enabled(), 'Tracing not running' trace_event.trace_disable() assert not trace_event.trace_is_enabled(), 'Tracing didnt disable properly.'
def stop_instrumenting(): trace_event.trace_disable() sys.settrace(None) threading.settrace(None)
def testDoubleDisable(self): with self._test_trace(): pass trace_event.trace_disable()
def DisableTracing(): if not trace_event.trace_is_enabled(): logging.warning('Tracing is not running.') else: trace_event.trace_disable()