Last active
January 3, 2025 13:16
-
-
Save jiffyclub/6b5e0f0f05ab487ff607 to your computer and use it in GitHub Desktop.
Convert a SnakeViz HTML file into a self-contained static file that can be hosted anywhere. This script replaces instances of static files being loaded from the local server by having them come from the rawgit CDN.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Prepare an HTML file from SnakeViz for use as a static page. | |
This makes it so all static files are loaded from a CDN instead | |
of from the local server. | |
To get the SnakeViz HTML file run the snakeviz CLI to load a profile | |
in your browser, than save that page as an HTML file to your computer. | |
Finally, run this script on that HTML file. | |
This script prints the modified HTML to stdout. | |
""" | |
from __future__ import print_function | |
import argparse | |
import re | |
import sys | |
# This regex excludes the lines in the Worker that look like | |
# event.data['url'] + "/static/vendor/immutable.min.js" | |
RESTR = r'(?<!] \+ ")/static/' | |
REPLACE_WITH = \ | |
'https://cdn.rawgit.com/jiffyclub/snakeviz/v0.4.2/snakeviz/static/' | |
def parse_args(args=None): | |
parser = argparse.ArgumentParser( | |
description=( | |
'Prepare an HTML file from SnakeViz for use as a static page. ' | |
'The modified HTML is printed to stdout.')) | |
parser.add_argument( | |
'htmlfile', type=argparse.FileType('r'), | |
help='HTML to convert to a static page.') | |
return parser.parse_args(args) | |
def main(args=None): | |
args = parse_args(args) | |
html = args.htmlfile.read() | |
print(re.sub(RESTR, REPLACE_WITH, html)) | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I created a script based on yours that does not require manual steps: https://gist.github.com/MSSandroid/6402e2e99e31633386a312b283839e0d