def ProcessHistogramDicts(histogram_dicts, options): """Convert histogram dicts to HTML and write output in output_dir.""" output_file = os.path.join(options.output_dir, OUTPUT_FILENAME) open(output_file, 'a').close() # Create file if it doesn't exist. with codecs.open(output_file, mode='r+', encoding='utf-8') as output_stream: vulcanize_histograms_viewer.VulcanizeAndRenderHistogramsViewer( histogram_dicts, output_stream, options.reset_results)
def Process(intermediate_results, options): """Process intermediate results and write output in output_dir.""" histogram_dicts = histograms_output.Convert(intermediate_results, options.results_label) output_file = os.path.join(options.output_dir, OUTPUT_FILENAME) open(output_file, 'a').close() # Create file if it doesn't exist. with codecs.open(output_file, mode='r+', encoding='utf-8') as output_stream: vulcanize_histograms_viewer.VulcanizeAndRenderHistogramsViewer( histogram_dicts, output_stream, options.reset_results)
def Format(self, page_test_results): histograms = page_test_results.AsHistogramDicts() vulcanize_histograms_viewer.VulcanizeAndRenderHistogramsViewer( histograms, self._output_stream, self._reset_results) if self._upload_bucket: file_path = os.path.abspath(self._output_stream.name) remote_path = ('html-results/results-%s' % datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')) try: url = cloud_storage.Insert(self._upload_bucket, remote_path, file_path) print 'View HTML results online at %s' % url except cloud_storage.PermissionError as e: logging.error('Cannot upload profiling files to cloud storage due to ' ' permission error: %s' % e.message)
def Profile(root, label=None, html_filename=None, html_stream=None, vulcanized_viewer=None, reset_results=False, diagnostics_callback=None): """Profiles memory consumed by the root object. Produces a HistogramSet containing 1 Histogram for each user-defined class encountered when recursing through the root object's properties. Each Histogram contains 1 sample for each instance of the class. Each sample contains 2 Breakdowns: - 'types' allows drilling down into memory profiles for other classes, and - 'properties' breaks down the size of an instance by its properties. Args: label: string label to distinguish these results from those produced by other Profile() calls. html_filename: string filename to write HTML results. html_stream: file-like string to write HTML results. vulcanized_viewer: HTML string reset_results: whether to delete pre-existing results in html_filename/html_stream diagnostics_callback: function that takes an instance of a class, and returns a dictionary from strings to Diagnostic objects. Returns: HistogramSet """ # TODO(4068): Package this and its dependencies and a vulcanized viewer in # order to remove the vulcanized_viewer parameter and simplify rendering the # viewer. profiler = _HeapProfiler(diagnostics_callback) histograms = profiler.Profile(root) if label: histograms.AddSharedDiagnosticToAllHistograms( reserved_infos.LABELS.name, generic_set.GenericSet([label])) if html_filename and not html_stream: open(html_filename, 'a').close() # Create file if it doesn't exist. html_stream = codecs.open(html_filename, mode='r+', encoding='utf-8') if html_stream: # Vulcanizing the viewer requires a full catapult checkout, which is not # available in some contexts such as appengine. # Merely rendering the viewer requires a pre-vulcanized viewer HTML string. # render_histograms_viewer does not require a full checkout, so it can run # in restricted contexts such as appengine as long as a pre-vulcanized # viewer is provided. if vulcanized_viewer: render_histograms_viewer.RenderHistogramsViewer( histograms.AsDicts(), html_stream, reset_results, vulcanized_viewer) else: from tracing_build import vulcanize_histograms_viewer vulcanize_histograms_viewer.VulcanizeAndRenderHistogramsViewer( histograms.AsDicts(), html_stream) return histograms