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 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 __init__(self, overhead_level=NO_OVERHEAD_LEVEL): """As the amount of instrumentation increases, so does the overhead. The user of the measurement chooses the overhead level that is appropriate, and the tracing is filtered accordingly. overhead_level: Can either be a custom TracingCategoryFilter object or one of NO_OVERHEAD_LEVEL, MINIMAL_OVERHEAD_LEVEL or DEBUG_OVERHEAD_LEVEL. """ self._category_filter = None if isinstance(overhead_level, tracing_category_filter.TracingCategoryFilter): self._category_filter = overhead_level elif overhead_level in ALL_OVERHEAD_LEVELS: if overhead_level == NO_OVERHEAD_LEVEL: self._category_filter = tracing_category_filter.CreateNoOverheadFilter( ) elif overhead_level == MINIMAL_OVERHEAD_LEVEL: self._category_filter = ( tracing_category_filter.CreateMinimalOverheadFilter()) else: self._category_filter = ( tracing_category_filter.CreateDebugOverheadFilter()) else: raise Exception( "Overhead level must be a TracingCategoryFilter object" " or valid overhead level string." " Given overhead level: %s" % overhead_level) self._tracing_options = tracing_options.TracingOptions() self._tracing_options.enable_chrome_trace = True self._tracing_options.enable_platform_display_trace = True
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 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 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 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 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 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): 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 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 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 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 testTracing(self): devtools_client = self._devtools_client if not devtools_client.IsChromeTracingSupported(): self.skipTest('Browser does not support tracing, skipping test.') # Start Chrome tracing. options = tracing_options.TracingOptions() options.enable_chrome_trace = True devtools_client.StartChromeTracing(options) # Stop Chrome tracing and check that the resulting data is valid. builder = trace_data.TraceDataBuilder() devtools_client.StopChromeTracing(builder) model.TimelineModel(builder.AsData())
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 testGetRendererThreadFromTabId(self): self.assertEquals(self._tab.url, 'about:blank') # Create 3 tabs. The third tab is closed before we call # tracing_controller.Start. first_tab = self._tab second_tab = self._browser.tabs.New() second_tab.Navigate('about:blank') second_tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() third_tab = self._browser.tabs.New() third_tab.Navigate('about:blank') third_tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() third_tab.Close() options = tracing_options.TracingOptions() options.enable_chrome_trace = True self._browser.platform.tracing_controller.Start( options, tracing_category_filter.CreateNoOverheadFilter()) first_tab.ExecuteJavaScript('console.time("first-tab-marker");') first_tab.ExecuteJavaScript('console.timeEnd("first-tab-marker");') second_tab.ExecuteJavaScript('console.time("second-tab-marker");') second_tab.ExecuteJavaScript('console.timeEnd("second-tab-marker");') trace_data = self._browser.platform.tracing_controller.Stop() timeline_model = model.TimelineModel(trace_data) # Assert that the renderer_thread of the first tab contains # 'first-tab-marker'. renderer_thread = timeline_model.GetRendererThreadFromTabId( first_tab.id) first_tab_markers = [ renderer_thread.IterAllSlicesOfName('first-tab-marker') ] self.assertEquals(1, len(first_tab_markers)) # Close second tab and assert that the renderer_thread of the second tab # contains 'second-tab-marker'. second_tab.Close() renderer_thread = timeline_model.GetRendererThreadFromTabId( second_tab.id) second_tab_markers = [ renderer_thread.IterAllSlicesOfName('second-tab-marker') ] self.assertEquals(1, len(second_tab_markers)) # Third tab wasn't available when we start tracing, so there is no # renderer_thread corresponding to it in the the trace. self.assertIs(None, timeline_model.GetRendererThreadFromTabId(third_tab.id))
def SetUp(self, page, tab): """Starts gathering timeline data. """ # Resets these member variables incase this object is reused. self._model = None self._renderer_process = None if not tab.browser.platform.tracing_controller.IsChromeTracingSupported( ): raise Exception('Not supported') category_filter = tracing_category_filter.TracingCategoryFilter( filter_string=self.trace_categories) for delay in page.GetSyntheticDelayCategories(): category_filter.AddSyntheticDelay(delay) options = tracing_options.TracingOptions() options.enable_chrome_trace = True tab.browser.platform.tracing_controller.Start(options, category_filter)
def testExceptionRaisedInStopTracing(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._tab.EvaluateJavaScript(""" window.__console_time = console.time; console.time = function() { }; """) with self.assertRaisesRegexp(Exception, 'Page stomped on console.time'): tracing_controller.Stop() # Tracing is stopped even if there is exception. self.assertFalse(tracing_controller.is_tracing_running)
def __init__(self, browser_backend, platform_backend, output_path, state, categories=None): super(TraceProfiler, self).__init__(browser_backend, platform_backend, output_path, state) assert self._browser_backend.supports_tracing # We always want flow events when tracing via telemetry. categories_with_flow = 'disabled-by-default-toplevel.flow' if categories: categories_with_flow += ',%s' % categories options = tracing_options.TracingOptions() options.enable_chrome_trace = True self._browser_backend.StartTracing(options, categories_with_flow, timeout=10)
def testHighlight(self): self.assertEquals(self._tab.url, 'about:blank') options = tracing_options.TracingOptions() options.enable_chrome_trace = True self._browser.platform.tracing_controller.Start( options, tracing_category_filter.CreateNoOverheadFilter()) self._tab.Highlight(rgba_color.WEB_PAGE_TEST_ORANGE) self._tab.ClearHighlight(rgba_color.WEB_PAGE_TEST_ORANGE) trace_data = self._browser.platform.tracing_controller.Stop() timeline_model = model.TimelineModel(trace_data) renderer_thread = timeline_model.GetRendererThreadFromTabId( self._tab.id) found_video_start_event = False for event in renderer_thread.async_slices: if event.name == '__ClearHighlight.video_capture_start': found_video_start_event = True break self.assertTrue(found_video_start_event)
def CreateAndRemoveTraceConfigFileOnDesktop(self, platform_backend): agent = chrome_tracing_agent.ChromeTracingAgent(platform_backend) config = tracing_config.TracingConfig( tracing_options.TracingOptions(), tracing_category_filter.TracingCategoryFilter()) config_file_path = os.path.join( chrome_tracing_agent._CHROME_TRACE_CONFIG_DIR_DESKTOP, chrome_tracing_agent._CHROME_TRACE_CONFIG_FILE_NAME) agent._CreateTraceConfigFileOnDesktop(config) self.assertTrue(os.path.exists(config_file_path)) with open(config_file_path, 'r') as f: config_file_str = f.read() self.assertEqual(config.GetTraceConfigJsonString(), config_file_str.strip()) agent._RemoveTraceConfigFileOnDesktop() self.assertFalse(os.path.exists(config_file_path)) # robust to multiple file removal agent._RemoveTraceConfigFileOnDesktop() self.assertFalse(os.path.exists(config_file_path))
def testCreateAndRemoveTraceConfigFileOnAndroid(self): platform_backend = FakeAndroidPlatformBackend() agent = chrome_tracing_agent.ChromeTracingAgent(platform_backend) config = tracing_config.TracingConfig( tracing_options.TracingOptions(), tracing_category_filter.TracingCategoryFilter()) config_file_path = os.path.join( chrome_tracing_agent._CHROME_TRACE_CONFIG_DIR_ANDROID, chrome_tracing_agent._CHROME_TRACE_CONFIG_FILE_NAME) agent._CreateTraceConfigFileOnAndroid(config) config_file_str = platform_backend.device.ReadFile(config_file_path, as_root=True) self.assertTrue(platform_backend.device.PathExists(config_file_path)) self.assertEqual(config.GetTraceConfigJsonString(), config_file_str.strip()) agent._RemoveTraceConfigFileOnAndroid() self.assertFalse(platform_backend.device.PathExists(config_file_path)) # robust to multiple file removal agent._RemoveTraceConfigFileOnAndroid() self.assertFalse(platform_backend.device.PathExists(config_file_path))
def VerifyIssuingInteractionRecords(self, **interaction_kwargs): action_runner = action_runner_module.ActionRunner(self._tab, skip_waits=True) self.Navigate('interaction_enabled_page.html') action_runner.Wait(1) options = tracing_options.TracingOptions() options.enable_chrome_trace = True self._browser.platform.tracing_controller.Start( options, tracing_category_filter.CreateNoOverheadFilter()) with action_runner.CreateInteraction('InteractionName', **interaction_kwargs): pass trace_data = self._browser.platform.tracing_controller.Stop() records = self.GetInteractionRecords(trace_data) self.assertEqual( 1, len(records), 'Failed to issue the interaction record on the tracing timeline.' ' Trace data:\n%s' % repr(trace_data._raw_data)) self.assertEqual('InteractionName', records[0].label) for attribute_name in interaction_kwargs: self.assertTrue(getattr(records[0], attribute_name))
def __init__(self, browser_backend, platform_backend, output_path, state, device=None): super(AndroidSystraceProfiler, self).__init__( browser_backend, platform_backend, output_path, state) assert self._browser_backend.supports_tracing self._output_path = output_path + '-trace.zip' self._systrace_output_path = output_path + '.systrace' # Use telemetry's own tracing backend instead the combined mode in # adb_profile_chrome because some benchmarks also do tracing of their own # and the two methods conflict. options = tracing_options.TracingOptions() options.enable_chrome_trace = True self._browser_backend.StartTracing(options, timeout=10) command = ['python', os.path.join(util.GetChromiumSrcDir(), 'tools', 'profile_chrome.py'), '--categories', '', '--continuous', '--output', self._systrace_output_path, '--json', '--systrace', ','.join(_SYSTRACE_CATEGORIES)] if device: command.extend(['--device', device]) self._profiler = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
def testDumpMemoryFailure(self): # Check that dumping memory before tracing starts raises an exception. self.assertRaises(Exception, self._browser.DumpMemory) # Start tracing with memory dumps disabled. options = tracing_options.TracingOptions() options.enable_chrome_trace = True self._tracing_controller.Start( options, tracing_category_filter.TracingCategoryFilter()) # Check that the method returns None if the dump was not successful. self.assertIsNone(self._browser.DumpMemory()) 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 no memory dumps. self.assertEqual(len(list(model.IterGlobalMemoryDumps())), 0)
def _StartupTracing(self, platform): # Stop browser browser_test_case.teardown_browser() # Start tracing self.assertFalse(platform.tracing_controller.is_tracing_running) trace_options = tracing_options.TracingOptions() trace_options.enable_chrome_trace = True category_filter = tracing_category_filter.TracingCategoryFilter() platform.tracing_controller.Start(trace_options, category_filter) self.assertTrue(platform.tracing_controller.is_tracing_running) try: # Start browser self.setUpClass() self._browser.tabs[0].Navigate('about:blank') self._browser.tabs[ 0].WaitForDocumentReadyStateToBeInteractiveOrBetter() self.assertEquals(platform, self._browser.platform) # Calling start tracing again will return False self.assertFalse( self._browser.platform.tracing_controller.Start( trace_options, category_filter)) trace_data = self._browser.platform.tracing_controller.Stop() # Test that trace data is parsable model_module.TimelineModel(trace_data) self.assertFalse( self._browser.platform.tracing_controller.is_tracing_running) # Calling stop tracing again will raise exception self.assertRaises(Exception, self._browser.platform.tracing_controller.Stop) finally: if self._browser: self._browser.Close() self._browser = None
def testCreateAndRemoveTraceConfigFileOnAndroid(self): platform_backend = FakeAndroidPlatformBackend() 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(platform_backend.device.PathExists(agent.trace_config_file)) config_file_str = platform_backend.device.ReadFile(agent.trace_config_file, as_root=True) self.assertEqual(agent._CreateTraceConfigFileString(config), config_file_str.strip()) config_file_path = agent.trace_config_file agent._RemoveTraceConfigFile() self.assertFalse(platform_backend.device.PathExists(config_file_path)) self.assertIsNone(agent.trace_config_file) # robust to multiple file removal agent._RemoveTraceConfigFile() self.assertFalse(platform_backend.device.PathExists(config_file_path)) self.assertIsNone(agent.trace_config_file)
binary_manager.InitDependencyManager(chromium_config.ChromiumConfig().client_config) from telemetry.timeline import tracing_category_filter from telemetry.timeline import tracing_options from json import dumps options = browser_options.BrowserFinderOptions(); parser = options.CreateParser(); (_, args) = parser.parse_args(); browserFactory = browser_finder.FindBrowser(options); with browserFactory.Create(options) as browser: tab = browser.tabs.New(); tab.Activate(); for i in browser.tabs: if i == tab: continue i.Close() category_filter = tracing_category_filter.TracingCategoryFilter() options = tracing_options.TracingOptions() options.enable_chrome_trace = True tab.Navigate(args[0]); tab.WaitForDocumentReadyStateToBeComplete(); tab.EvaluateJavaScript("(function() { document.documentElement.style.display = 'none'; return document.body.offsetTop; })()"); browser.platform.tracing_controller.Start(options, category_filter); tab.EvaluateJavaScript("(function() { document.documentElement.style.display = 'block'; return document.body.offsetTop; })()"); browser.platform.tracing_controller.Stop().Serialize(sys.stdout);
def WillNavigateToPageInner(self, page, tab): cat_string = ','.join(TOPLEVEL_CATEGORIES) cat_filter = tracing_category_filter.TracingCategoryFilter(cat_string) options = tracing_options.TracingOptions() options.enable_chrome_trace = True tab.browser.platform.tracing_controller.Start(options, cat_filter, 60)