示例#1
0
def CaptureProfile(options,
                   interval,
                   modules,
                   output=None,
                   compress=False,
                   write_json=False):
    """Records a profiling trace saves the result to a file.

  Args:
    options: Command line options.
    interval: Time interval to capture in seconds. An interval of None (or 0)
        continues tracing until stopped by the user.
    modules: The list of modules to initialize the tracing controller with.
    output: Output file name or None to use an automatically generated name.
    compress: If True, the result will be compressed either with gzip or zip
        depending on the number of captured subtraces.
    write_json: If True, prefer JSON output over HTML.

  Returns:
    Path to saved profile.
  """
    agents_with_config = tracing_controller.CreateAgentsWithConfig(
        options, modules)
    if chrome_startup_tracing_agent in modules:
        controller_config = tracing_controller.GetChromeStartupControllerConfig(
            options)
    else:
        controller_config = tracing_controller.GetControllerConfig(options)
    controller = tracing_controller.TracingController(agents_with_config,
                                                      controller_config)
    try:
        result = controller.StartTracing()
        trace_type = controller.GetTraceType()
        if not result:
            ui.PrintMessage('Trace starting failed.')
        if interval:
            ui.PrintMessage(
                ('Capturing %d-second %s. Press Enter to stop early...' %
                 (interval, trace_type)),
                eol='')
            ui.WaitForEnter(interval)
        else:
            ui.PrintMessage('Capturing %s. Press Enter to stop...' %
                            trace_type,
                            eol='')
            raw_input()

        ui.PrintMessage('Stopping...')
        all_results = controller.StopTracing()
    finally:
        if interval:
            ui.PrintMessage('done')

    return _GetResults(all_results, controller, output, compress, write_json,
                       interval)
示例#2
0
def CaptureProfile(agents,
                   interval,
                   output=None,
                   compress=False,
                   write_json=False):
    """Records a profiling trace saves the result to a file.

  Args:
    agents: List of tracing agents.
    interval: Time interval to capture in seconds. An interval of None (or 0)
        continues tracing until stopped by the user.
    output: Output file name or None to use an automatically generated name.
    compress: If True, the result will be compressed either with gzip or zip
        depending on the number of captured subtraces.
    write_json: If True, prefer JSON output over HTML.

  Returns:
    Path to saved profile.
  """
    trace_type = ' + '.join(map(str, agents))
    try:
        _StartTracing(agents)
        if interval:
            ui.PrintMessage(
                ('Capturing %d-second %s. Press Enter to stop early...' %
                 (interval, trace_type)),
                eol='')
            ui.WaitForEnter(interval)
        else:
            ui.PrintMessage('Capturing %s. Press Enter to stop...' %
                            trace_type,
                            eol='')
            raw_input()
    finally:
        _StopTracing(agents)
    if interval:
        ui.PrintMessage('done')

    return _GetResults(agents, output, compress, write_json, interval)