# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import cProfile import io import logging import os import pstats import re from pstats import Stats from snakeviz.stats import json_stats, table_rows from tornado import template module_found = True try: import snakeviz except ImportError: module_found = False snakeviz_dir = os.path.dirname(os.path.abspath(snakeviz.__file__)) snakeviz_templates_dir = os.path.join(snakeviz_dir, "templates") def _from_pstat_to_static_html(stats: Stats, html_filename: str): """ Parses pstats data and populates viz.html template stored under templates dir. This utility allows to export html file without kicking off webserver. Note that it relies js scripts stored at rawgit cdn. This is not super reliable, however it does allow one to not have to rely on webserver and local rendering. On the other hand, for local rendering please follow the main snakeviz tutorial Inspiration for this util is from https://gist.github.com/jiffyclub/6b5e0f0f05ab487ff607. Args: stats: Stats generated from cProfile data html_filename: Output filename in which populated template is rendered """ RESTR = r'(?