def testIncludeAndExcludeCategoryRaisesAssertion(self): a = tracing_category_filter.TracingCategoryFilter() a.AddIncludedCategory('foo') self.assertRaises(AssertionError, a.AddExcludedCategory, 'foo') a = tracing_category_filter.TracingCategoryFilter() a.AddExcludedCategory('foo') self.assertRaises(AssertionError, a.AddIncludedCategory, 'foo') self.assertRaises(AssertionError, tracing_category_filter.TracingCategoryFilter, 'foo,-foo') self.assertRaises(AssertionError, tracing_category_filter.TracingCategoryFilter, '-foo,foo')
def testStartAndStopTraceMultipleTimes(self): options = tracing_options.TracingOptions() options.enable_chrome_trace = True self._tracing_controller.Start( options, tracing_category_filter.TracingCategoryFilter()) self.assertFalse( self._tracing_controller.Start( options, tracing_category_filter.TracingCategoryFilter())) trace_data = self._tracing_controller.Stop() # Test that trace data is parsable model_module.TimelineModel(trace_data) self.assertFalse(self._tracing_controller.is_tracing_running) # Calling stop again will raise exception self.assertRaises(Exception, self._tracing_controller.Stop)
def WillNavigateToPage(self, page, tab): tab.ExecuteJavaScript(""" if (window.chrome && chrome.gpuBenchmarking && chrome.gpuBenchmarking.clearImageCache) { chrome.gpuBenchmarking.clearImageCache(); } """) self._power_metric.Start(page, tab) options = tracing_options.TracingOptions() options.enable_chrome_trace = True # FIXME: Remove the timeline category when impl-side painting is on # everywhere. category_filter = tracing_category_filter.TracingCategoryFilter( 'disabled-by-default-devtools.timeline') # FIXME: Remove webkit.console when blink.console lands in chromium and # the ref builds are updated. crbug.com/386847 # FIXME: Remove the devtools.timeline category when impl-side painting is # on everywhere. categories = [ 'blink', 'devtools.timeline', 'webkit.console', 'blink.console' ] for c in categories: category_filter.AddIncludedCategory(c) tab.browser.platform.tracing_controller.Start(options, category_filter)
def testModifiedConsoleTime(self): tracing_controller = self._tab.browser.platform.tracing_controller category_filter = tracing_category_filter.TracingCategoryFilter() options = tracing_options.TracingOptions() options.enable_chrome_trace = True tracing_controller.Start(options, category_filter) self.Navigate('blank.html') self.assertEquals( self._tab.EvaluateJavaScript('document.location.pathname;'), '/blank.html') self._tab.EvaluateJavaScript(""" window.__console_time = console.time; console.time = function() { }; """) with self.assertRaisesRegexp(Exception, 'Page stomped on console.time'): tracing_controller.Stop() # Restore console.time self._tab.EvaluateJavaScript(""" console.time = window.__console_time; delete window.__console_time; """) # Check that subsequent tests will be able to use tracing normally. self.assertFalse(tracing_controller.is_tracing_running) tracing_controller.Start(options, category_filter) self.assertTrue(tracing_controller.is_tracing_running) tracing_controller.Stop() self.assertFalse(tracing_controller.is_tracing_running)
def testDumpMemorySuccess(self): # Check that dumping memory before tracing starts raises an exception. self.assertRaises(Exception, self._browser.DumpMemory) # Start tracing with memory dumps enabled. options = tracing_options.TracingOptions() options.enable_chrome_trace = True self._tracing_controller.Start( options, tracing_category_filter.TracingCategoryFilter( 'disabled-by-default-memory-infra')) # Request several memory dumps in a row and test that they were all # succesfully created with unique IDs. expected_dump_ids = [] for _ in xrange(self._REQUESTED_DUMP_COUNT): dump_id = self._browser.DumpMemory() self.assertIsNotNone(dump_id) self.assertNotIn(dump_id, expected_dump_ids) expected_dump_ids.append(dump_id) trace_data = self._tracing_controller.Stop() # Check that dumping memory after tracing stopped raises an exception. self.assertRaises(Exception, self._browser.DumpMemory) # Test that trace data is parsable. model = model_module.TimelineModel(trace_data) self.assertGreater(len(model.processes), 0) # Test that the resulting model contains the requested memory dumps in the # correct order (and nothing more). actual_dump_ids = [d.dump_id for d in model.IterGlobalMemoryDumps()] self.assertEqual(actual_dump_ids, expected_dump_ids)
def testBasic(self): category_filter = tracing_category_filter.TracingCategoryFilter( 'x,-y,disabled-by-default-z,DELAY(7;foo)') config = chrome_trace_config.ChromeTraceConfig() config.SetTracingCategoryFilter(category_filter) config.enable_systrace = True config.record_mode = chrome_trace_config.RECORD_UNTIL_FULL # Trace config for startup tracing. self.assertEquals( { 'enable_systrace': True, 'excluded_categories': ['y'], 'included_categories': ['x', 'disabled-by-default-z'], 'record_mode': 'record-until-full', 'synthetic_delays': ['DELAY(7;foo)'] }, config.GetChromeTraceConfigForStartupTracing()) # Trace config for DevTools (modern API). self.assertEquals( { 'enableSystrace': True, 'excludedCategories': ['y'], 'includedCategories': ['x', 'disabled-by-default-z'], 'recordMode': 'recordUntilFull', 'syntheticDelays': ['DELAY(7;foo)'] }, config.GetChromeTraceConfigForDevTools()) # Trace categories and options for DevTools (legacy API). self.assertFalse(config.requires_modern_devtools_tracing_start_api) self.assertEquals( ('x,disabled-by-default-z,-y,DELAY(7;foo)', 'record-until-full,enable-systrace'), config.GetChromeTraceCategoriesAndOptionsForDevTools())
def CreateTimelineBasedMeasurementOptions(self): category_filter = tracing_category_filter.TracingCategoryFilter( filter_string='webrtc,webkit.console,blink.console') options = timeline_based_measurement.Options(category_filter) options.SetTimelineBasedMetrics( [webrtc_rendering_timeline.WebRtcRenderingTimelineMetric()]) return options
def testCreateAndRemoveTraceConfigFileOnDesktop(self): platform_backend = FakeDesktopPlatformBackend() agent = chrome_tracing_agent.ChromeTracingAgent(platform_backend) self.assertIsNone(agent.trace_config_file) config = tracing_config.TracingConfig( tracing_options.TracingOptions(), tracing_category_filter.TracingCategoryFilter()) agent._CreateTraceConfigFile(config) self.assertIsNotNone(agent.trace_config_file) self.assertTrue(os.path.exists(agent.trace_config_file)) self.assertTrue(os.stat(agent.trace_config_file).st_mode & stat.S_IROTH) with open(agent.trace_config_file, 'r') as f: config_file_str = f.read() self.assertEqual(agent._CreateTraceConfigFileString(config), config_file_str.strip()) config_file_path = agent.trace_config_file agent._RemoveTraceConfigFile() self.assertFalse(os.path.exists(config_file_path)) self.assertIsNone(agent.trace_config_file) # robust to multiple file removal agent._RemoveTraceConfigFile() self.assertFalse(os.path.exists(config_file_path)) self.assertIsNone(agent.trace_config_file)
def setUp(self): self._trace_options = tracing_options.TracingOptions() self._trace_options.enable_platform_display_trace = True self._category_filter = tracing_category_filter.TracingCategoryFilter() self._platform_backend = FakeAndroidPlatformBackend() self._agent = display_tracing_agent.DisplayTracingAgent( self._platform_backend)
def testFirstPaintMetricSmoke(self): ps = self.CreateEmptyPageSet() ps.AddStory(TestTimelinebasedMeasurementPage(ps, ps.base_dir)) cat_filter = tracing_category_filter.TracingCategoryFilter( filter_string= '*,blink.console,navigation,blink.user_timing,loading,' + 'devtools.timeline,disabled-by-default-blink.debug.layout') options = tbm_module.Options(overhead_level=cat_filter) options.SetTimelineBasedMetric('firstPaintMetric') tbm = tbm_module.TimelineBasedMeasurement(options) results = self.RunMeasurement(tbm, ps, self._options) self.assertEquals(0, len(results.failures), results.failures) v_fcp_max = results.FindAllPageSpecificValuesNamed( 'firstContentfulPaint_max') self.assertEquals(len(v_fcp_max), 1) self.assertIsNotNone(v_fcp_max[0].page) # TODO(kouhei): enable this once the reference build of telemetry is # updated. # self.assertGreater(v_fcp_max[0].value, 0) v_fmp_max = results.FindAllPageSpecificValuesNamed( 'firstMeaningfulPaint_max') self.assertEquals(len(v_fmp_max), 1)
def CreateTimelineBasedMeasurementOptions(self): options = timeline_based_measurement.Options( tracing_category_filter.TracingCategoryFilter( '-*,disabled-by-default-memory-infra')) options.config.enable_android_graphics_memtrack = True options.SetTimelineBasedMetric('memoryMetric') return options
def CreateTimelineBasedMeasurementOptions(self): options = timeline_based_measurement.Options() options.config.SetTracingCategoryFilter( tracing_category_filter.TracingCategoryFilter(','.join( self.TRACING_CATEGORIES))) options.SetTimelineBasedMetric('SystemHealthMetrics') return options
def CreateTimelineBasedMeasurementOptions(self): cat_string = ','.join(TOPLEVEL_CATEGORIES) cat_filter = tracing_category_filter.TracingCategoryFilter(cat_string) options = timeline_based_measurement.Options(overhead_level=cat_filter) options.SetTimelineBasedMetrics([gpu_timeline.GPUTimelineMetric()]) return options
def CreateTimelineBasedMeasurementOptions(self): startup_category_filter = tracing_category_filter.TracingCategoryFilter( filter_string='startup,blink.user_timing') options = timeline_based_measurement.Options( overhead_level=startup_category_filter) options.SetTimelineBasedMetrics( [startup.StartupTimelineMetric()]) return options
def testDefault(self): options = tracing_options.TracingOptions() category_filter = tracing_category_filter.TracingCategoryFilter() config = tracing_config.TracingConfig(options, category_filter) config_string = config.GetTraceConfigJsonString() self.assertEquals( '{' '"record_mode": "record-as-much-as-possible"' '}', config_string)
def CreateTimelineBasedMeasurementOptions(self): media_router_category = 'media_router' category_filter = tracing_category_filter.TracingCategoryFilter( media_router_category) category_filter.AddIncludedCategory('blink.console') options = timeline_based_measurement.Options(category_filter) options.SetLegacyTimelineBasedMetrics( [media_router_timeline_metric.MediaRouterMetric()]) return options
def CreateTimelineBasedMeasurementOptions(self): # Enable only memory-infra, to get memory dumps, and blink.console, to get # the timeline markers used for mapping threads to tabs. trace_memory = tracing_category_filter.TracingCategoryFilter( filter_string='-*,blink.console,disabled-by-default-memory-infra') tbm_options = timeline_based_measurement.Options( overhead_level=trace_memory) tbm_options.config.enable_android_graphics_memtrack = True return tbm_options
def StartTracing(self, platform_backend, enable_chrome_trace=True): assert chrome_tracing_agent.ChromeTracingAgent.IsSupported(platform_backend) agent = chrome_tracing_agent.ChromeTracingAgent(platform_backend) trace_options = tracing_options.TracingOptions() trace_options.enable_chrome_trace = enable_chrome_trace category_filter = tracing_category_filter.TracingCategoryFilter('foo') agent._platform_backend.tracing_controller_backend.is_tracing_running = True agent.Start(trace_options, category_filter, 10) return agent
def __init__(self): # Trace options. self.enable_chrome_trace = False self.enable_platform_display_trace = False self.enable_android_graphics_memtrack = False self._record_mode = RECORD_AS_MUCH_AS_POSSIBLE self._enable_systrace = False # Tracing category filter. self._tracing_category_filter = ( tracing_category_filter.TracingCategoryFilter())
def testGotTrace(self): options = tracing_options.TracingOptions() options.enable_chrome_trace = True self._tracing_controller.Start( options, tracing_category_filter.TracingCategoryFilter()) trace_data = self._tracing_controller.Stop() # Test that trace data is parsable model = model_module.TimelineModel(trace_data) assert len(model.processes) > 0
def WillNavigateToPage(self, page, tab): # FIXME: Remove webkit.console when blink.console lands in chromium and the # ref builds are updated. crbug.com/386847 custom_categories = ['webkit.console', 'blink.console', 'gpu'] category_filter = tracing_category_filter.TracingCategoryFilter() for c in custom_categories: category_filter.AddIncludedCategory(c) options = tracing_options.TracingOptions() options.enable_chrome_trace = True tab.browser.platform.tracing_controller.Start(options, category_filter, 60)
def WillNavigateToPage(self, page, tab): category_filter = tracing_category_filter.TracingCategoryFilter() for category in self._CATEGORIES: category_filter.AddIncludedCategory(category) options = tracing_options.TracingOptions() options.enable_chrome_trace = True tab.browser.platform.tracing_controller.Start( options, category_filter, self._TIME_OUT_IN_SECONDS)
def CreateTimelineBasedMeasurementOptions(self): v8_categories = [ 'blink.console', 'renderer.scheduler', 'v8', 'webkit.console' ] memory_categories = 'blink.console,disabled-by-default-memory-infra' category_filter = tracing_category_filter.TracingCategoryFilter( memory_categories) for category in v8_categories: category_filter.AddIncludedCategory(category) options = timeline_based_measurement.Options(category_filter) return options
def CreateTimelineBasedMeasurementOptions(self): v8_categories = [ 'blink.console', 'renderer.scheduler', 'v8', 'webkit.console' ] memory_categories = [ 'blink.console', 'disabled-by-default-memory-infra' ] category_filter = tracing_category_filter.TracingCategoryFilter( ','.join(['-*'] + v8_categories + memory_categories)) options = timeline_based_measurement.Options(category_filter) options.SetTimelineBasedMetric('v8AndMemoryMetrics') return options
def testIsTracingRunning(self): tracing_controller = self._browser.platform.tracing_controller if not tracing_controller.IsChromeTracingSupported(): return self.assertFalse(tracing_controller.is_tracing_running) options = tracing_options.TracingOptions() options.enable_chrome_trace = True category_filter = tracing_category_filter.TracingCategoryFilter() tracing_controller.Start(options, category_filter) self.assertTrue(tracing_controller.is_tracing_running) tracing_controller.Stop() self.assertFalse(tracing_controller.is_tracing_running)
def testBasic(self): f = tracing_category_filter.TracingCategoryFilter( 'x,-y,disabled-by-default-z,DELAY(7;foo)') self.assertEquals(set(['x']), set(f.included_categories)) self.assertEquals(set(['y']), set(f.excluded_categories)) self.assertEquals(set(['disabled-by-default-z']), set(f.disabled_by_default_categories)) self.assertEquals(set(['DELAY(7;foo)']), set(f.synthetic_delays)) self.assertTrue('x' in f.filter_string) self.assertEquals('x,disabled-by-default-z,-y,DELAY(7;foo)', f.stable_filter_string)
def testModifiedConsoleTime(self): category_filter = tracing_category_filter.TracingCategoryFilter() options = tracing_options.TracingOptions() options.enable_chrome_trace = True self._tab.browser.platform.tracing_controller.Start(options, category_filter) self.Navigate('blank.html') self.assertEquals( self._tab.EvaluateJavaScript('document.location.pathname;'), '/blank.html') self._tab.EvaluateJavaScript('console.time = function() { };') with self.assertRaisesRegexp(Exception, 'Page stomped on console.time'): self._tab.browser.platform.tracing_controller.Stop()
def WillNavigateToPage(self, page, tab): tracing_controller = tab.browser.platform.tracing_controller # FIXME: Remove webkit.console when blink.console lands in chromium and # the ref builds are updated. crbug.com/386847 custom_categories = [ 'webkit.console', 'blink.console', 'benchmark', 'trace_event_overhead' ] category_filter = tracing_category_filter.TracingCategoryFilter( ','.join(custom_categories)) self._tbm = timeline_based_measurement.TimelineBasedMeasurement( timeline_based_measurement.Options(category_filter), self._results_wrapper) self._tbm.WillRunStoryForPageTest(tracing_controller, page.GetSyntheticDelayCategories())
def testBasic(self): options = tracing_options.TracingOptions() options.record_mode = tracing_options.RECORD_UNTIL_FULL options.enable_systrace = True category_filter = tracing_category_filter.TracingCategoryFilter( 'x,-y,disabled-by-default-z,DELAY(7;foo)') config = tracing_config.TracingConfig(options, category_filter) config_string = config.GetTraceConfigJsonString() self.assertEquals( '{' '"enable_systrace": true, ' '"excluded_categories": ["y"], ' '"included_categories": ["x", "disabled-by-default-z"], ' '"record_mode": "record-until-full", ' '"synthetic_delays": ["DELAY(7;foo)"]' '}', config_string)
def CreateTimelineBasedMeasurementOptions(self): v8_gc_latency_categories = [ 'blink.console', 'renderer.scheduler', 'v8', 'webkit.console'] smoothness_categories = [ 'webkit.console', 'blink.console', 'benchmark', 'trace_event_overhead'] categories = list(set(v8_gc_latency_categories + smoothness_categories)) memory_categories = 'blink.console,disabled-by-default-memory-infra' category_filter = tracing_category_filter.TracingCategoryFilter( memory_categories) for category in categories: category_filter.AddIncludedCategory(category) options = timeline_based_measurement.Options(category_filter) options.SetTimelineBasedMetrics([v8_gc_latency.V8GCLatency(), smoothness.SmoothnessMetric(), memory_timeline.MemoryTimelineMetric()]) return options