Steps
Ask the user which script to profile (full or relative path).
Run py-spy to record the profile. The output is always written to
profile.speedscope.jsonin the current directory.Linux (no sudo needed):
pixi run -e profiling pyspy script.pymacOS (sudo required — py-spy needs to attach to the process):
sudo pixi run -e profiling pyspy script.pyIf sudo fails to find the pixi environment, use absolute paths:
sudo /path/to/.pixi/envs/profiling/bin/py-spy record --gil \ -o profile.speedscope.json --format speedscope \ -- /path/to/.pixi/envs/profiling/bin/python script.pyOpen the result in speedscope:
pixi run -e profiling speedscopeThis opens
profile.speedscope.jsonin the browser via the local speedscope CLI.
Notes
- If the speedscope view is blank, switch threads using the thread selector in the top-right corner.
- To save a profile before overwriting:
cp profile.speedscope.json profile-before.speedscope.json --gilrecords only time when the GIL is held (Python-level CPU time). Drop it to include C extension time.- speedscope must be installed globally:
npm install -g speedscope