示例#1
0
def main_impl(arguments):
    # Parse the command line options.
    options, categories = parse_options(arguments)

    # Override --atrace-categories and --ftrace-categories flags if command-line
    # categories are provided.
    if categories:
        if options.target == 'android':
            options.atrace_categories = categories
        elif options.target == 'linux':
            options.ftrace_categories = categories
        else:
            raise RuntimeError(
                'Categories are only valid for atrace/ftrace. Target '
                'platform must be either Android or Linux.')

    if options.target == 'android' and not options.from_file:
        initialize_devil()
        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]

    # If list_categories is selected, just print the list of categories.
    # In this case, use of the tracing controller is not necessary.
    if options.list_categories:
        if options.target == 'android':
            atrace_agent.list_categories(options)
        elif options.target == 'linux':
            ftrace_agent.list_categories(options)
        return

    # Set up the systrace runner and start tracing.
    controller = systrace_runner.SystraceRunner(
        os.path.dirname(os.path.abspath(__file__)), options)
    controller.StartTracing()

    # Wait for the given number of seconds or until the user presses enter.
    # pylint: disable=superfluous-parens
    # (need the parens so no syntax error if trying to load with Python 3)
    if options.from_file is not None:
        print('Reading results from file.')
    elif options.trace_time:
        print('Starting tracing (%d seconds)' % options.trace_time)
        time.sleep(options.trace_time)
    else:
        raw_input('Starting tracing (stop with enter)')

    # Stop tracing and collect the output.
    print('Tracing completed. Collecting output...')
    controller.StopTracing()
    print('Outputting Systrace results...')
    controller.OutputSystraceResults(write_json=options.write_json)
示例#2
0
def main_impl(arguments):
  # Parse the command line options.
  options, categories = parse_options(arguments)

  # Override --atrace-categories and --ftrace-categories flags if command-line
  # categories are provided.
  if categories:
    if options.target == 'android':
      options.atrace_categories = categories
    elif options.target == 'linux':
      options.ftrace_categories = categories
    else:
      raise RuntimeError('Categories are only valid for atrace/ftrace. Target '
                         'platform must be either Android or Linux.')

  # Include atrace categories by default in Systrace.
  if options.target == 'android' and not options.atrace_categories:
    options.atrace_categories = atrace_agent.DEFAULT_CATEGORIES

  if options.target == 'android' and not options.from_file:
    initialize_devil()
    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]

  # If list_categories is selected, just print the list of categories.
  # In this case, use of the tracing controller is not necessary.
  if options.list_categories:
    if options.target == 'android':
      atrace_agent.list_categories(options)
    elif options.target == 'linux':
      ftrace_agent.list_categories(options)
    return

  # Set up the systrace runner and start tracing.
  controller = systrace_runner.SystraceRunner(
      os.path.dirname(os.path.abspath(__file__)), options)
  controller.StartTracing()

  # Wait for the given number of seconds or until the user presses enter.
  # pylint: disable=superfluous-parens
  # (need the parens so no syntax error if trying to load with Python 3)
  if options.from_file is not None:
    print('Reading results from file.')
  elif options.trace_time:
    print('Starting tracing (%d seconds)' % options.trace_time)
    time.sleep(options.trace_time)
  else:
    raw_input('Starting tracing (stop with enter)')

  # Stop tracing and collect the output.
  print('Tracing completed. Collecting output...')
  controller.StopTracing()
  print('Outputting Systrace results...')
  controller.OutputSystraceResults(write_json=options.write_json)
示例#3
0
def main():
  options, categories = parse_options(sys.argv)
  agents = create_agents(options)

  if not agents:
    dirs = DEFAULT_AGENT_DIR
    if options.agent_dirs:
      dirs += ',' + options.agent_dirs
    sys.stderr.write('No systrace agent is available in directories |%s|.\n' %
                     dirs)
    sys.exit(1)

  try:
    from . import update_systrace_trace_viewer
  except ImportError:
    pass
  else:
    update_systrace_trace_viewer.update()

  if options.target == 'android' and not options.device_serial:
    devices = get_device_serials()
    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 = devices[0]

  if options.list_categories:
    if options.target == 'android':
      atrace_agent.list_categories(options)
    elif options.target == 'linux':
      ftrace_agent.list_categories(options)
    return

  for a in agents:
    a.StartAgentTracing(options, categories, 10)

  if options.trace_time:
    print 'Tracing running for %d seconds.' % options.trace_time
    time.sleep(options.trace_time)
  else:
    print 'Tracing running, stop with ENTER.'
    raw_input()

  for a in agents:
    a.StopAgentTracing(10)

  results = []
  for a in agents:
    new_result = a.GetResults(30)
    results.append(new_result)

  script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
  write_trace_html(options.output_file, script_dir, results)
示例#4
0
def main():
    # Parse the command line options.
    options, categories = parse_options(sys.argv)

    initialize_devil()

    if options.target == 'android' and not options.device_serial_number:
        devices = util.get_device_serials()
        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]

    # If list_categories is selected, just print the list of categories.
    # In this case, use of the tracing controller is not necessary.
    if options.list_categories:
        if options.target == 'android':
            atrace_agent.list_categories(options)
        elif options.target == 'linux':
            ftrace_agent.list_categories(options)
        return

    # Set up the systrace runner and start tracing.
    script_dir = os.path.dirname(os.path.abspath(__file__))
    controller = systrace_runner.SystraceRunner(script_dir, options,
                                                categories)
    controller.StartTracing()

    # Wait for the given number of seconds or until the user presses enter.
    # pylint: disable=superfluous-parens
    # (need the parens so no syntax error if trying to load with Python 3)
    if options.from_file is not None:
        print('Reading results from file.')
    elif options.trace_time:
        print('Starting tracing (%d seconds)' % options.trace_time)
        time.sleep(options.trace_time)
    else:
        raw_input('Starting tracing (stop with enter)')

    # Stop tracing and collect the output.
    print('Tracing completed. Collecting output...')
    controller.StopTracing()
    print('Outputting Systrace results...')
    controller.OutputSystraceResults(write_json=options.write_json)
示例#5
0
def main():
  # Parse the command line options.
  options, categories = parse_options(sys.argv)

  if options.target == 'android' and not options.device_serial_number:
    devices = get_device_serials()
    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]

  # If list_categories is selected, just print the list of categories.
  # In this case, use of the tracing controller is not necessary.
  if options.list_categories:
    if options.target == 'android':
      atrace_agent.list_categories(options)
    elif options.target == 'linux':
      ftrace_agent.list_categories(options)
    return

  # Set up the systrace runner and start tracing.
  script_dir = os.path.dirname(os.path.abspath(__file__))
  controller = systrace_runner.SystraceRunner(
      script_dir, options, categories)
  controller.StartTracing()

  # Wait for the given number of seconds or until the user presses enter.
  # pylint: disable=superfluous-parens
  # (need the parens so no syntax error if trying to load with Python 3)
  if options.from_file is not None:
    print('Reading results from file.')
  elif options.trace_time:
    print('Starting tracing (%d seconds)' % options.trace_time)
    time.sleep(options.trace_time)
  else:
    raw_input('Starting tracing (stop with enter)')


  # Stop tracing and collect the output.
  print('Tracing completed. Collecting output...')
  controller.StopTracing()
  print('Outputting Systrace results...')
  controller.OutputSystraceResults(write_json=options.write_json)