Speedscope is an excellent profile viewer. Maybe you're recorded a profile with py-spy and you want to show it to other people in a GitHub issue. The speedscope app can render profiles from a URL, but where do you store the profile?
You can do this easily with gists, githack, and a little script:
- Install the GitHub CLI
- Add
gistscope.sh
to somewhere on your$PATH
(andchmod +x
it)
Record your profile(s). (Tip: give them meaningful filenames.)
$ gh gist create --public profile1.json profile2.json
- Creating gist with multiple files
✓ Created gist profile2.json
https://gist.github.com/e43edda6735bff455343559535acf973
Open the gist in your browser, and for each file, right-click on the Raw
button and "Copy link", then paste the raw link as an input to the gistscope
command:
$ gistscope https://gist.github.com/gjoseph92/e43edda6735bff455343559535acf973/raw/435de16c7e083dcdf28e6fc9163f9fada4f88ac7/profile1.json https://gist.github.com/gjoseph92/e43edda6735bff455343559535acf973/raw/5f95d64913a1dfdfdb8fc5b65413eabe23113aa9/profile2.json
* [`profile1.json`](https://speedscope.app#profileURL=https%3a%2f%2fgistcdn.githack.com%2fgjoseph92%2fe43edda6735bff455343559535acf973%2fraw%2f435de16c7e083dcdf28e6fc9163f9fada4f88ac7%2fprofile1.json)
* [`profile2.json`](https://speedscope.app#profileURL=https%3a%2f%2fgistcdn.githack.com%2fgjoseph92%2fe43edda6735bff455343559535acf973%2fraw%2f5f95d64913a1dfdfdb8fc5b65413eabe23113aa9%2fprofile2.json)
It'll give you a markdown-formatted list of links that anyone can click on to view your profile in speedscope.app. The profile data is served from your gist over the GitHack CDN (allowing CORS).
macOS tip to copy the output directly to the clipboard:
$ gistscope <input1> <input2> | pbcopy
Obviously the script could be improved to get the raw links for you from the gist, saving you the browser step, but the GitHub CLI doesn't make this easy. So it didn't seem Worth The Time.