Esempio n. 1
0
def _GetResults(trace_results, controller, output, compress, write_json,
                interval):
    ui.PrintMessage('Downloading...')

    # Wait for the trace file to get written.
    time.sleep(1)

    for agent in controller.get_child_agents:
        if isinstance(agent, chrome_tracing_agent.ChromeTracingAgent):
            time.sleep(interval / 4)

    # Ignore the systraceController because it will not contain any results,
    # instead being in charge of collecting results.
    trace_results = [
        x for x in controller.all_results
        if not (x.source_name == 'systraceController')
    ]

    if not trace_results:
        ui.PrintMessage('No results')
        return ''

    result = None
    trace_results = output_generator.MergeTraceResultsIfNeeded(trace_results)
    if not write_json:
        ui.PrintMessage('Writing trace HTML...')
        html_file = output or trace_results[0].source_name + '.html'
        result = output_generator.GenerateHTMLOutput(trace_results, html_file)
        ui.PrintMessage('\nWrote file://%s' % result)
    elif compress and len(trace_results) == 1:
        result = output or trace_results[0].source_name + '.gz'
        util.WriteDataToCompressedFile(trace_results[0].raw_data, result)
    elif len(trace_results) > 1:
        result = (output
                  or 'chrome-combined-trace-%s.zip' % util.GetTraceTimestamp())
        util.ArchiveData(trace_results, result)
    elif output:
        result = output
        with open(result, 'wb') as f:
            f.write(trace_results[0].raw_data)
    else:
        result = trace_results[0].source_name
        with open(result, 'wb') as f:
            f.write(trace_results[0].raw_data)

    return result
Esempio n. 2
0
def _GetResults(agents, output, compress, write_json, interval):
    ui.PrintMessage('Downloading...', eol='')

    # Wait for the trace file to get written.
    time.sleep(1)

    trace_results = []
    for agent in agents:
        if isinstance(agent, chrome_tracing_agent.ChromeTracingAgent):
            time.sleep(interval / 4)
        trace_results.append(agent.GetResults())

    if not trace_results:
        ui.PrintMessage('No results')
        return ''

    result = None
    trace_results = output_generator.MergeTraceResultsIfNeeded(trace_results)
    if not write_json:
        print 'Writing trace HTML'
        html_file = trace_results[0].source_name + '.html'
        result = output_generator.GenerateHTMLOutput(trace_results, html_file)
        print '\nWrote file://%s\n' % result
    elif compress and len(trace_results) == 1:
        result = output or trace_results[0].source_name + '.gz'
        util.WriteDataToCompressedFile(trace_results[0].raw_data, result)
    elif len(trace_results) > 1:
        result = (output
                  or 'chrome-combined-trace-%s.zip' % util.GetTraceTimestamp())
        util.ArchiveData(trace_results, result)
    elif output:
        result = output
        with open(result, 'wb') as f:
            f.write(trace_results[0].raw_data)
    else:
        result = trace_results[0].source_name
        with open(result, 'wb') as f:
            f.write(trace_results[0].raw_data)

    return result