def WriteHTMLForTracesToFile(trace_filenames, output_file, config_name=None): trace_data_list = [] for filename in trace_filenames: with open(filename, 'r') as f: trace_data = f.read() try: trace_data = json.loads(trace_data) except ValueError: pass trace_data_list.append(trace_data) title = os.path.basename(output).split('_')[0] + ": Intel(R) Single Event API" trace2html.WriteHTMLForTraceDataToFile(trace_data_list, title, output_file, config_name)
def _GetTempFileHandle(self, trace_data): if self.page: title = self.page.display_name else: title = '' content = StringIO.StringIO() trace2html.WriteHTMLForTraceDataToFile( [trace_data.GetEventsFor(trace_data_module.CHROME_TRACE_PART)], title, content) tf = tempfile.NamedTemporaryFile(delete=False, suffix='.html') tf.write(content.getvalue().encode('utf-8')) tf.close() return file_handle.FromTempFile(tf)
def WriteTraces(output_filename, traces): if output_filename.endswith(GZIP_FILENAME_SUFFIX): with gzip.open(output_filename, 'wb') as f: json.dump(_ConcatTraces(traces), f) elif output_filename.endswith(HTML_FILENAME_SUFFIX): with codecs.open(output_filename, mode='w', encoding='utf-8') as f: trace2html.WriteHTMLForTraceDataToFile( traces, 'Chrome trace with Snapdragon profiler data', f) elif output_filename.endswith(JSON_FILENAME_SUFFIX): with open(output_filename, 'w') as f: json.dump(_ConcatTraces(traces), f) else: raise Exception('Unknown trace file suffix: %s', output_filename)
def SlimTrace(trace_file_handle, slimmed_trace_path): traces = None for extractor in ALL_TRACE_EXTRACTORS: if extractor.CanExtractFile(trace_file_handle): traces = extractor.ExtractTracesFromFile(trace_file_handle) break if traces is None: raise Exception('Cannot extrac trace from %s' % trace_file_handle.name) slimmed_traces = map(SlimSingleTrace, traces) with codecs.open(slimmed_trace_path, mode='w', encoding='utf-8') as f: trace2html.WriteHTMLForTraceDataToFile( slimmed_traces, title='', output_file=f)
def SaveTrace(trace, filename): """Save a JSON trace to a (possibly gzipped) file.""" if filename is None: logging.info('Dumping trace to standard output...') print(json.dumps(trace)) else: logging.info('Saving trace %r...', filename) if filename.endswith(HTML_FILENAME_SUFFIX): with codecs.open(filename, mode='w', encoding='utf-8') as f: trace2html.WriteHTMLForTraceDataToFile([trace], 'Merged trace', f) elif filename.endswith(GZIP_FILENAME_SUFFIX): with gzip.open(filename, 'wb') as f: json.dump(trace, f) else: with open(filename, 'w') as f: json.dump(trace, f)