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 testAddMetadataInJsonFormatRaises(self): with self._test_trace(format=trace_event.JSON): with self.assertRaises(log.TraceException): trace_event.trace_add_benchmark_metadata( benchmark_start_time_us=1000, story_run_time_us=2000, benchmark_name='benchmark', benchmark_description='description', story_name='story', story_tags=['tag1', 'tag2'], story_run_index=0, )
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 RecordBenchmarkMetadata(results): """Record benchmark metadata if tracing is enabled.""" if IsAgentEnabled(): trace_event.trace_add_benchmark_metadata( benchmark_name=results.benchmark_name, benchmark_description=results.benchmark_description, benchmark_start_time_us=results.benchmark_start_us, label=results.label, story_run_time_us=results.current_story_run.start_us, story_name=results.current_story.name, story_tags=results.current_story.GetStoryTagsList(), story_run_index=results.current_story_run.index, ) else: logging.warning( 'Telemetry tracing agent is not enabled. Discarding Telemetry info.' )
def SetTelemetryInfo(telemetry_info): """Record Telemetry metadata if tracing is enabled.""" if IsAgentEnabled(): trace_event.trace_add_benchmark_metadata( benchmark_start_time_us=telemetry_info.benchmark_start_us, story_run_time_us=telemetry_info.trace_start_us, benchmark_name=telemetry_info.benchmark_name, benchmark_description=telemetry_info.benchmark_descriptions, story_name=telemetry_info.story_display_name, story_tags=telemetry_info.GetStoryTagsList(), story_run_index=telemetry_info.storyset_repeat_counter, label=telemetry_info.label, had_failures=telemetry_info.had_failures, trace_url=telemetry_info.trace_url, ) else: logging.warning( 'Telemetry tracing agent is not enabled. Discarding Telemetry info.')
def RecordBenchmarkMetadata(results): """Record benchmark metadata if tracing is enabled.""" if IsAgentEnabled(): # TODO(crbug.com/973837): Get the data we need directly from the results # object, rather than having to go through the private _telemetry_info attr. telemetry_info = results._telemetry_info trace_event.trace_add_benchmark_metadata( benchmark_name=results.benchmark_name, benchmark_description=results.benchmark_description, benchmark_start_time_us=results.benchmark_start_us, label=results.label, story_run_time_us=telemetry_info.trace_start_us, story_name=telemetry_info.story_display_name, story_tags=telemetry_info.GetStoryTagsList(), story_run_index=telemetry_info.storyset_repeat_counter, had_failures=telemetry_info.had_failures, ) else: logging.warning( 'Telemetry tracing agent is not enabled. Discarding Telemetry info.' )