def testCaptureBasicProfile(self): result = profiler.CaptureProfile(self._tracing_options, 1, [fake_agent_1]) try: self.assertTrue(os.path.exists(result)) self.assertTrue(result.endswith('.html')) finally: if os.path.exists(result): os.remove(result)
def testCaptureJsonProfile(self): controller = FakeController() result = profiler.CaptureProfile([controller], 1, write_json=True) try: self.assertFalse(result.endswith('.html')) with open(result) as f: self.assertEquals(f.read(), controller.contents) finally: os.remove(result)
def testCaptureMultipleProfiles(self): agents = [FakeAgent('c1'), FakeAgent('c2')] result = profiler.CaptureProfile(agents, 1, write_json=True) try: self.assertTrue(result.endswith('.zip')) self.assertTrue(zipfile.is_zipfile(result)) finally: if os.path.exists(result): os.remove(result)
def testCaptureMultipleProfiles(self): result = profiler.CaptureProfile(self._tracing_options, 1, [fake_agent_1, fake_agent_2], write_json=True) try: self.assertTrue(result.endswith('.zip')) self.assertTrue(zipfile.is_zipfile(result)) finally: if os.path.exists(result): os.remove(result)
def testCaptureJsonProfile(self): result = profiler.CaptureProfile(self._tracing_options, 1, [fake_agent_2], write_json=True) try: self.assertFalse(result.endswith('.html')) with open(result) as f: self.assertEquals(f.read(), 'fake-contents') finally: if os.path.exists(result): os.remove(result)
def testCaptureJsonProfile(self): agent = FakeAgent() result = profiler.CaptureProfile([agent], 1, write_json=True) try: self.assertFalse(result.endswith('.html')) with open(result) as f: self.assertEquals(f.read(), agent.contents) finally: if os.path.exists(result): os.remove(result)
def testCaptureBasicProfile(self): agent = FakeAgent() result = profiler.CaptureProfile([agent], 1) try: self.assertTrue(agent.stopped) self.assertTrue(os.path.exists(result)) self.assertTrue(result.endswith('.html')) finally: if os.path.exists(result): os.remove(result)
def testCaptureBasicProfile(self): controller = FakeController() interval = 1.5 result = profiler.CaptureProfile([controller], interval) try: self.assertEquals(controller.interval, interval) self.assertTrue(controller.stopped) self.assertTrue(os.path.exists(result)) self.assertTrue(result.endswith('.html')) finally: os.remove(result)
def testCaptureMultipleProfiles(self): controllers = [FakeController('c1'), FakeController('c2')] result = profiler.CaptureProfile(controllers, 1, write_json=True) try: self.assertTrue(result.endswith('.zip')) self.assertTrue(zipfile.is_zipfile(result)) with zipfile.ZipFile(result) as f: self.assertEquals( f.namelist(), [controllers[0].filename[1:], controllers[1].filename[1:]]) finally: os.remove(result)
def main(): parser = _CreateOptionParser() options, _ = parser.parse_args() if options.verbose: logging.getLogger().setLevel(logging.DEBUG) devices = device_utils.DeviceUtils.HealthyDevices() if len(devices) != 1: logging.error('Exactly 1 device must be attached.') return 1 device = devices[0] package_info = profiler.GetSupportedBrowsers()[options.browser] if options.systrace_categories in ['list', 'help']: ui.PrintMessage('\n'.join( systrace_controller.SystraceController.GetCategories(device))) return 0 systrace_categories = (options.systrace_categories.split(',') if options.systrace_categories else []) enabled_controllers = [] # Enable the systrace and chrome controller. The systrace controller should go # first because otherwise the resulting traces miss early systrace data. if systrace_categories: enabled_controllers.append( systrace_controller.SystraceController(device, systrace_categories, False)) enabled_controllers.append( chrome_startup_controller.ChromeStartupTracingController( device, package_info, options.cold, options.url)) if options.output: options.output = os.path.expanduser(options.output) result = profiler.CaptureProfile(enabled_controllers, options.time, output=options.output, compress=options.compress, write_json=options.json) if options.view: if sys.platform == 'darwin': os.system('/usr/bin/open %s' % os.path.abspath(result)) else: webbrowser.open(result)
def main(): parser = _CreateOptionParser() options, _args = parser.parse_args() # pylint: disable=unused-variable if options.trace_cc: parser.error("""--trace-cc is deprecated. For basic jank busting uses, use --trace-frame-viewer For detailed study of ubercompositor, pass --trace-ubercompositor. When in doubt, just try out --trace-frame-viewer. """) if options.verbose: logging.getLogger().setLevel(logging.DEBUG) if not options.device_serial_number: devices = [ a.GetDeviceSerial() for a in adb_wrapper.AdbWrapper.Devices() ] if len(devices) == 0: raise RuntimeError('No ADB devices connected.') elif len(devices) >= 2: raise RuntimeError( 'Multiple devices connected, serial number required') options.device_serial_number = devices[0] device = device_utils.DeviceUtils.HealthyDevices( device_arg=options.device_serial_number)[0] package_info = util.get_supported_browsers()[options.browser] options.device = device options.package_info = package_info # Include Chrome categories by default in profile_chrome. if not options.chrome_categories: options.chrome_categories = chrome_tracing_agent.DEFAULT_CHROME_CATEGORIES if options.chrome_categories in ['list', 'help']: ui.PrintMessage('Collecting record categories list...', eol='') record_categories = [] disabled_by_default_categories = [] record_categories, disabled_by_default_categories = \ chrome_tracing_agent.ChromeTracingAgent.GetCategories( device, package_info) ui.PrintMessage('done') ui.PrintMessage('Record Categories:') ui.PrintMessage('\n'.join('\t%s' % item \ for item in sorted(record_categories))) ui.PrintMessage('\nDisabled by Default Categories:') ui.PrintMessage('\n'.join('\t%s' % item \ for item in sorted(disabled_by_default_categories))) return 0 if options.atrace_categories in ['list', 'help']: atrace_agent.list_categories(atrace_agent.get_config(options)) print '\n' return 0 if (perf_tracing_agent.PerfProfilerAgent.IsSupported() and options.perf_categories in ['list', 'help']): ui.PrintMessage('\n'.join( perf_tracing_agent.PerfProfilerAgent.GetCategories(device))) return 0 if not options.trace_time and not options.continuous: ui.PrintMessage( 'Time interval or continuous tracing should be specified.') return 1 if (options.chrome_categories and options.atrace_categories and 'webview' in options.atrace_categories): logging.warning('Using the "webview" category in atrace together with ' 'Chrome tracing results in duplicate trace events.') if options.output_file: options.output_file = os.path.expanduser(options.output_file) result = profiler.CaptureProfile( options, options.trace_time if not options.continuous else 0, _PROFILE_CHROME_AGENT_MODULES, output=options.output_file, compress=options.compress, write_json=options.write_json) if options.view: if sys.platform == 'darwin': os.system('/usr/bin/open %s' % os.path.abspath(result)) else: webbrowser.open(result)
def main(): parser = _CreateOptionParser() options, _args = parser.parse_args() if options.trace_cc: parser.parse_error("""--trace-cc is deprecated. For basic jank busting uses, use --trace-frame-viewer For detailed study of ubercompositor, pass --trace-ubercompositor. When in doubt, just try out --trace-frame-viewer. """) if options.verbose: logging.getLogger().setLevel(logging.DEBUG) devices = device_utils.DeviceUtils.HealthyDevices() device = None if options.device: device = next((d for d in devices if d == options.device), None) elif len(devices) == 1: device = devices[0] if not device: parser.error('Use -d/--device to select a device:\n' + '\n'.join(devices)) package_info = profiler.GetSupportedBrowsers()[options.browser] if options.chrome_categories in ['list', 'help']: ui.PrintMessage('Collecting record categories list...', eol='') record_categories = [] disabled_by_default_categories = [] record_categories, disabled_by_default_categories = \ chrome_controller.ChromeTracingController.GetCategories( device, package_info) ui.PrintMessage('done') ui.PrintMessage('Record Categories:') ui.PrintMessage('\n'.join('\t%s' % item \ for item in sorted(record_categories))) ui.PrintMessage('\nDisabled by Default Categories:') ui.PrintMessage('\n'.join('\t%s' % item \ for item in sorted(disabled_by_default_categories))) return 0 if options.systrace_categories in ['list', 'help']: ui.PrintMessage('\n'.join( systrace_controller.SystraceController.GetCategories(device))) return 0 if (perf_controller.PerfProfilerController.IsSupported() and options.perf_categories in ['list', 'help']): ui.PrintMessage('\n'.join( perf_controller.PerfProfilerController.GetCategories(device))) return 0 if not options.time and not options.continuous: ui.PrintMessage( 'Time interval or continuous tracing should be specified.') return 1 chrome_categories = _ComputeChromeCategories(options) systrace_categories = _ComputeSystraceCategories(options) perf_categories = _ComputePerfCategories(options) if chrome_categories and 'webview' in systrace_categories: logging.warning( 'Using the "webview" category in systrace together with ' 'Chrome tracing results in duplicate trace events.') enabled_controllers = [] if chrome_categories: enabled_controllers.append( chrome_controller.ChromeTracingController(device, package_info, chrome_categories, options.ring_buffer, options.trace_memory)) if systrace_categories: enabled_controllers.append( systrace_controller.SystraceController(device, systrace_categories, options.ring_buffer)) if perf_categories: enabled_controllers.append( perf_controller.PerfProfilerController(device, perf_categories)) if options.ddms: enabled_controllers.append( ddms_controller.DdmsController(device, package_info)) if not enabled_controllers: ui.PrintMessage('No trace categories enabled.') return 1 if options.output: options.output = os.path.expanduser(options.output) result = profiler.CaptureProfile( enabled_controllers, options.time if not options.continuous else 0, output=options.output, compress=options.compress, write_json=options.json) if options.view: if sys.platform == 'darwin': os.system('/usr/bin/open %s' % os.path.abspath(result)) else: webbrowser.open(result)
def main(): parser = _CreateOptionParser() options, _args = parser.parse_args() # pylint: disable=unused-variable if options.trace_cc: parser.error("""--trace-cc is deprecated. For basic jank busting uses, use --trace-frame-viewer For detailed study of ubercompositor, pass --trace-ubercompositor. When in doubt, just try out --trace-frame-viewer. """) if options.verbose: logging.getLogger().setLevel(logging.DEBUG) device = device_utils.DeviceUtils.HealthyDevices( device_arg=options.device_serial_number)[0] package_info = profiler.GetSupportedBrowsers()[options.browser] options.device = device options.package_info = package_info # Add options that are present in Systrace but not in profile_chrome (since # they both use the same tracing controller). # TODO(washingtonp): Once Systrace uses all of the profile_chrome agents, # manually setting these options will no longer be necessary and should be # removed. options.list_categories = None options.link_assets = None options.asset_dir = None options.timeout = None options.collection_timeout = None options.target = None if options.chrome_categories in ['list', 'help']: ui.PrintMessage('Collecting record categories list...', eol='') record_categories = [] disabled_by_default_categories = [] record_categories, disabled_by_default_categories = \ chrome_tracing_agent.ChromeTracingAgent.GetCategories( device, package_info) ui.PrintMessage('done') ui.PrintMessage('Record Categories:') ui.PrintMessage('\n'.join('\t%s' % item \ for item in sorted(record_categories))) ui.PrintMessage('\nDisabled by Default Categories:') ui.PrintMessage('\n'.join('\t%s' % item \ for item in sorted(disabled_by_default_categories))) return 0 if options.atrace_categories in ['list', 'help']: ui.PrintMessage('\n'.join( atrace_tracing_agent.AtraceAgent.GetCategories(device))) return 0 if (perf_tracing_agent.PerfProfilerAgent.IsSupported() and options.perf_categories in ['list', 'help']): ui.PrintMessage('\n'.join( perf_tracing_agent.PerfProfilerAgent.GetCategories(device))) return 0 if not options.trace_time and not options.continuous: ui.PrintMessage( 'Time interval or continuous tracing should be specified.') return 1 if options.chrome_categories and 'webview' in options.atrace_categories: logging.warning('Using the "webview" category in atrace together with ' 'Chrome tracing results in duplicate trace events.') if options.output_file: options.output_file = os.path.expanduser(options.output_file) result = profiler.CaptureProfile( options, options.trace_time if not options.continuous else 0, _PROFILE_CHROME_AGENT_MODULES, output=options.output_file, compress=options.compress, write_json=options.write_json) if options.view: if sys.platform == 'darwin': os.system('/usr/bin/open %s' % os.path.abspath(result)) else: webbrowser.open(result)
def main(): parser = _CreateOptionParser() options, _args = parser.parse_args() if options.trace_cc: parser.parse_error("""--trace-cc is deprecated. For basic jank busting uses, use --trace-frame-viewer For detailed study of ubercompositor, pass --trace-ubercompositor. When in doubt, just try out --trace-frame-viewer. """) if options.verbose: logging.getLogger().setLevel(logging.DEBUG) devices = android_commands.GetAttachedDevices() if len(devices) != 1: parser.error('Exactly 1 device must be attached.') device = device_utils.DeviceUtils(devices[0]) package_info = profiler.GetSupportedBrowsers()[options.browser] if options.chrome_categories in ['list', 'help']: ui.PrintMessage('Collecting record categories list...', eol='') record_categories = [] disabled_by_default_categories = [] record_categories, disabled_by_default_categories = \ chrome_controller.ChromeTracingController.GetCategories( device, package_info) ui.PrintMessage('done') ui.PrintMessage('Record Categories:') ui.PrintMessage('\n'.join('\t%s' % item \ for item in sorted(record_categories))) ui.PrintMessage('\nDisabled by Default Categories:') ui.PrintMessage('\n'.join('\t%s' % item \ for item in sorted(disabled_by_default_categories))) return 0 if options.systrace_categories in ['list', 'help']: ui.PrintMessage('\n'.join( systrace_controller.SystraceController.GetCategories(device))) return 0 if (perf_controller.PerfProfilerController.IsSupported() and options.perf_categories in ['list', 'help']): ui.PrintMessage('\n'.join( perf_controller.PerfProfilerController.GetCategories(device))) return 0 if not options.time and not options.continuous: ui.PrintMessage( 'Time interval or continuous tracing should be specified.') return 1 chrome_categories = _ComputeChromeCategories(options) systrace_categories = _ComputeSystraceCategories(options) perf_categories = _ComputePerfCategories(options) if chrome_categories and 'webview' in systrace_categories: logging.warning( 'Using the "webview" category in systrace together with ' 'Chrome tracing results in duplicate trace events.') enabled_controllers = [] if chrome_categories: enabled_controllers.append( chrome_controller.ChromeTracingController(device, package_info, chrome_categories, options.ring_buffer, options.trace_memory)) if systrace_categories: enabled_controllers.append( systrace_controller.SystraceController(device, systrace_categories, options.ring_buffer)) if perf_categories: enabled_controllers.append( perf_controller.PerfProfilerController(device, perf_categories)) if not enabled_controllers: ui.PrintMessage('No trace categories enabled.') return 1 if options.output: options.output = os.path.expanduser(options.output) result = profiler.CaptureProfile( enabled_controllers, options.time if not options.continuous else 0, output=options.output, compress=options.compress, write_json=options.json) if options.view_canary: if sys.platform == 'darwin': os.system(( '/usr/bin/open -a /Applications/Google\ Chrome\ Canary.app %s ' '--args --enable-impl-side-painting --enable-skia-benchmarking ' '--allow-webui-compositing') % os.path.abspath(result)) else: _PrintMessage( 'No Chrome Canary on this platform to open trace in, try a different view method' ) elif options.view: if sys.platform == 'darwin': os.system('/usr/bin/open %s' % os.path.abspath(result)) else: webbrowser.open(result) elif options.run_tev and result: os.system('trace-event-viewer %s' % result)
if (perf_tracing_agent.PerfProfilerAgent.IsSupported() and options.perf_categories in ['list', 'help']): ui.PrintMessage('\n'.join( perf_tracing_agent.PerfProfilerAgent.GetCategories(presentation.device))) return 0 if not options.trace_time and not options.continuous: ui.PrintMessage('Time interval or continuous tracing should be specified.') return 1 if (options.chrome_categories and options.atrace_categories and 'webview' in options.atrace_categories): logging.warning('Using the "webview" category in atrace together with ' 'Chrome tracing results in duplicate trace events.') if options.output_file: options.output_file = os.path.expanduser(options.output_file) result = profiler.CaptureProfile( options, options.trace_time if not options.continuous else 0, _PROFILE_CHROME_AGENT_MODULES, output=options.output_file, compress=options.compress, write_json=options.write_json) if options.view: if sys.platform == 'darwin': os.system('/usr/bin/open %s' % os.path.abspath(result)) else: webbrowser.open(result)