jlfwong / speedscope

🔬 A fast, interactive web-based viewer for performance profiles.
https://www.speedscope.app
MIT License
5.59k stars 247 forks source link

Add note about pyinstrument support wiki page #377

Closed joerick closed 2 years ago

joerick commented 3 years ago

Hello @jlfwong !

Thanks to the efforts of @goxberry over in https://github.com/joerick/pyinstrument/pull/160, my profiler pyinstrument now supports speedscope JSON as an output. I thought you might want to mention it in your README.

I couldn't create the wiki page myself, but if you're able to copy paste this as a new page into the wiki that should work:

Importing from pyinstrument (python)

pyinstrument is a statistical profiler for Python.

pyinstrument has an explicit output format for speedscope (See: https://github.com/joerick/pyinstrument/pull/160).

To profile a Python script and view the output in speedscope, run:

    pyinstrument -r speedscope -o profile.speedscope.json your_script.py

Or, you can profile a specific block of code using:

    from pyinstrument import Profiler
    from pyinstrument.renderers import SpeedscopeRenderer

    with Profiler() as profiler:
        ... # your code here

    with open('profile.speedscope.json', 'w') as f:
        f.write(profiler.render(renderer=SpeedscopeRenderer()))

Then drop the resulting profile.speedscope.json into https://www.speedscope.app/
jlfwong commented 2 years ago

Thanks!