예제 #1
0
def _CreateOptionParser():
    parser = optparse.OptionParser(
        description='Record about://tracing profiles '
        'from Android browsers. See http://dev.'
        'chromium.org/developers/how-tos/trace-event-'
        'profiling-tool for detailed instructions for '
        'profiling.',
        conflict_handler='resolve')

    parser = util.get_main_options(parser)

    timed_options = optparse.OptionGroup(parser, 'Timed tracing')
    timed_options.add_option('-t',
                             '--time',
                             help='Profile for N seconds and '
                             'download the resulting trace.',
                             metavar='N',
                             type='float',
                             dest='trace_time')
    parser.add_option_group(timed_options)

    cont_options = optparse.OptionGroup(parser, 'Continuous tracing')
    cont_options.add_option('--continuous',
                            help='Profile continuously until '
                            'stopped.',
                            action='store_true')
    cont_options.add_option('--ring-buffer',
                            help='Use the trace buffer as a '
                            'ring buffer and save its contents when stopping '
                            'instead of appending events into one long trace.',
                            action='store_true')
    parser.add_option_group(cont_options)

    parser.add_option_group(flags.OutputOptions(parser))

    browsers = sorted(util.get_supported_browsers().keys())
    parser.add_option('-b',
                      '--browser',
                      help='Select among installed browsers. '
                      'One of ' + ', '.join(browsers) +
                      ', "stable" is used by '
                      'default.',
                      type='choice',
                      choices=browsers,
                      default='stable')
    parser.add_option('-v',
                      '--verbose',
                      help='Verbose logging.',
                      action='store_true')
    parser.add_option('-z',
                      '--compress',
                      help='Compress the resulting trace '
                      'with gzip. ',
                      action='store_true')

    # Add options from profile_chrome agents.
    for module in _PROFILE_CHROME_AGENT_MODULES:
        parser.add_option_group(module.add_options(parser))

    return parser
  def test_tracing(self):
    TRACE_BUFFER_SIZE = '16384'
    TRACE_TIME = '5'

    devices = device_utils.DeviceUtils.HealthyDevices()
    package_info = util.get_supported_browsers()['stable']
    device = devices[0]
    with tempfile_ext.TemporaryFileName() as output_file_name:
      # Launch the browser before tracing.
      device.StartActivity(
          intent.Intent(activity=package_info.activity,
                        package=package_info.package,
                        data='about:blank',
                        extras={'create_new_tab': True}),
          blocking=True, force_stop=True)

      # Run atrace agent.
      run_systrace.main_impl(['./run_systrace.py',
                              '-b',
                              TRACE_BUFFER_SIZE,
                              '-t',
                              TRACE_TIME,
                              '-o',
                              output_file_name,
                              '-e',
                              str(device),
                              '--atrace-categories=gfx,input,view'])

      # Verify results.
      with open(output_file_name, 'r') as f:
        full_trace = f.read()
      self.assertTrue('CPU#' in full_trace)
예제 #3
0
    def test_tracing(self):
        TRACE_BUFFER_SIZE = '16384'
        TRACE_TIME = '5'

        devices = device_utils.DeviceUtils.HealthyDevices()
        package_info = util.get_supported_browsers()['stable']
        presentation.device = devices[0]
        output_file_name = util.generate_random_filename_for_test()

        try:
            # Launch the browser before tracing.
            presentation.device.StartActivity(intent.Intent(
                activity=package_info.activity,
                package=package_info.package,
                data='about:blank',
                extras={'create_new_tab': True}),
                                              blocking=True,
                                              force_stop=True)

            # Run atrace agent.
            run_systrace.main_impl([
                './run_systrace.py', '-b', TRACE_BUFFER_SIZE, '-t', TRACE_TIME,
                '-o', output_file_name, '-e',
                str(presentation.device), '--atrace-categories=gfx,input,view'
            ])

            # Verify results.
            with open(output_file_name, 'r') as f:
                full_trace = f.read()
                self.assertTrue('CPU#' in full_trace)
        except:
            raise
        finally:
            if os.path.exists(output_file_name):
                os.remove(output_file_name)
예제 #4
0
    def test_tracing(self):
        TRACE_BUFFER_SIZE = '16384'
        TRACE_TIME = '5'

        devices = device_utils.DeviceUtils.HealthyDevices()
        package_info = util.get_supported_browsers()['stable']
        device = devices[0]
        with tempfile_ext.TemporaryFileName() as output_file_name:
            # Launch the browser before tracing.
            device.StartActivity(intent.Intent(activity=package_info.activity,
                                               package=package_info.package,
                                               data='about:blank',
                                               extras={'create_new_tab':
                                                       True}),
                                 blocking=True,
                                 force_stop=True)

            # Run atrace agent.
            run_systrace.main_impl([
                './run_systrace.py', '-b', TRACE_BUFFER_SIZE, '-t', TRACE_TIME,
                '-o', output_file_name, '-e',
                str(device), '--atrace-categories=gfx,input,view'
            ])

            # Verify results.
            with open(output_file_name, 'r') as f:
                full_trace = f.read()
            self.assertTrue('CPU#' in full_trace)
예제 #5
0
  def setUp(self):
    devices = device_utils.DeviceUtils.HealthyDevices()
    self.browser = 'stable'
    self.package_info = util.get_supported_browsers()[self.browser]
    self.device = devices[0]

    curr_browser = self.GetChromeProcessID()
    if curr_browser == None:
      self.StartBrowser()
예제 #6
0
    def setUp(self):
        devices = device_utils.DeviceUtils.HealthyDevices()
        self.browser = 'stable'
        self.package_info = util.get_supported_browsers()[self.browser]
        self.device = devices[0]

        curr_browser = self.GetChromeProcessID()
        if curr_browser == None:
            self.StartBrowser()
예제 #7
0
def _CreateOptionParser():
  parser = optparse.OptionParser(description='Record about://tracing profiles '
                                 'from Android browsers. See http://dev.'
                                 'chromium.org/developers/how-tos/trace-event-'
                                 'profiling-tool for detailed instructions for '
                                 'profiling.', conflict_handler='resolve')

  parser = util.get_main_options(parser)

  timed_options = optparse.OptionGroup(parser, 'Timed tracing')
  timed_options.add_option('-t', '--time', help='Profile for N seconds and '
                          'download the resulting trace.', metavar='N',
                           type='float', dest='trace_time')
  parser.add_option_group(timed_options)

  cont_options = optparse.OptionGroup(parser, 'Continuous tracing')
  cont_options.add_option('--continuous', help='Profile continuously until '
                          'stopped.', action='store_true')
  cont_options.add_option('--ring-buffer', help='Use the trace buffer as a '
                          'ring buffer and save its contents when stopping '
                          'instead of appending events into one long trace.',
                          action='store_true')
  parser.add_option_group(cont_options)

  parser.add_option_group(flags.OutputOptions(parser))

  browsers = sorted(util.get_supported_browsers().keys())
  parser.add_option('-b', '--browser', help='Select among installed browsers. '
                    'One of ' + ', '.join(browsers) + ', "stable" is used by '
                    'default.', type='choice', choices=browsers,
                    default='stable')
  parser.add_option('-v', '--verbose', help='Verbose logging.',
                    action='store_true')
  parser.add_option('-z', '--compress', help='Compress the resulting trace '
                    'with gzip. ', action='store_true')

  # Add options from profile_chrome agents.
  for module in _PROFILE_CHROME_AGENT_MODULES:
    parser.add_option_group(module.add_options(parser))

  return parser
예제 #8
0
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)
예제 #9
0
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.
""")

  logging.basicConfig()

  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)
예제 #10
0
def ProfileOptions(parser):
  """Build option group for profiling chrome.

  Args:
    parser: OptionParser object for parsing the command-line.

  Returns:
    Option group that contains profiling chrome options.
  """
  profile_options = optparse.OptionGroup(parser, 'Profile Chrome Options')
  browsers = sorted(util.get_supported_browsers().keys())

  profile_options.add_option('-b',
                             '--browser',
                             help='Select among installed browsers. '
                             'One of ' + ', '.join(browsers) +
                             '. "stable" is used by '
                             'default.',
                             type='choice',
                             choices=browsers,
                             default='stable')
  profile_options.add_option('-t',
                             '--time',
                             help=('Stops tracing after N seconds. '
                                   'Default is 5 seconds'),
                             default=5,
                             metavar='N',
                             type='int',
                             dest='trace_time')
  profile_options.add_option('-e',
                             '--serial',
                             help='adb device serial number.',
                             type='string',
                             default=util.get_default_serial(),
                             dest='device_serial_number')
  profile_options.add_option('-f',
                             '--trace_format',
                             help='Format of saved trace: proto, json, html.'
                             ' Default is proto.',
                             default='proto',
                             dest='trace_format')
  profile_options.add_option('-p',
                             '--platform',
                             help='Device platform. Only Android is supported.',
                             default='android',
                             dest='platform')
  profile_options.add_option('--buf-size',
                             help='Use a trace buffer size '
                             ' of N KB.',
                             type='int',
                             metavar='N',
                             dest='trace_buf_size')
  profile_options.add_option(
      '--enable_profiler',
      help='Comma-separated string of '
      'profiling options to use. Supports options for memory or '
      'cpu or both. Ex: --enable_profiler=memory '
      'or --enable_profiler=memory,cpu. ',
      dest='enable_profiler')
  profile_options.add_option('--chrome_categories',
                             help='Chrome tracing '
                             'categories to record.',
                             type='string',
                             default=_DEFAULT_CHROME_CATEGORIES)
  profile_options.add_option(
      '--skip_symbolize',
      help='Skips symbolization after recording trace profile, if specified.',
      action='store_true',
      dest='skip_symbolize')
  profile_options.add_option('--compress',
                             help='Compress the resulting trace '
                             'with gzip. ',
                             action='store_true')

  # This is kept for backwards compatibility. Help is suppressed because this
  # should be specified through the newer |trace_format| flag.
  profile_options.add_option('--json',
                             help=optparse.SUPPRESS_HELP,
                             dest='write_json')

  return profile_options
예제 #11
0
  logging.basicConfig()

  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]
  presentation.device = device_utils.DeviceUtils.HealthyDevices(device_arg=
      options.device_serial_number)[0]
  package_info = util.get_supported_browsers()[options.browser]

  options.presentation.device = presentation.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(
            presentation.device, package_info)