def testJsonTraceMerging(self): update_systrace_trace_viewer.update(force_update=True) self.assertTrue(os.path.exists( update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE)) t1 = "{'traceEvents': [{'ts': 123, 'ph': 'b'}]}" t2 = "{'traceEvents': [], 'stackFrames': ['blah']}" results = [trace_result.TraceResult('a', t1), trace_result.TraceResult('b', t2)] merged_results = output_generator.MergeTraceResultsIfNeeded(results) for r in merged_results: if r.source_name == 'a': self.assertEquals(r.raw_data, t1) elif r.source_name == 'b': self.assertEquals(r.raw_data, t2) self.assertEquals(len(merged_results), len(results)) os.remove(update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE)
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
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