Skip to content

Commit 244f17d

Browse files
authored
PYTHON-5404 - Add docs + justfile target for profiling execution (#2402)
1 parent 65f7c54 commit 244f17d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,15 @@ partially-converted asynchronous version of the same name to the `test/asynchron
460460
Use this generated file as a starting point for the completed conversion.
461461

462462
The script is used like so: `python tools/convert_test_to_async.py [test_file.py]`
463+
464+
## Generating a flame graph using py-spy
465+
To profile a test script and generate a flame graph, follow these steps:
466+
1. Install `py-spy` if you haven't already:
467+
```bash
468+
pip install py-spy
469+
```
470+
2. Inside your test script, perform any required setup and then loop over the code you want to profile for improved sampling.
471+
3. Run `py-spy record -o <output.svg> -r <sample_rate=100> -- python <path/to/script>` to generate a `.svg` file containing the flame graph.
472+
(Note: on macOS you will need to run this command using `sudo` to allow `py-spy` to attach to the Python process.)
473+
4. If you need to include native code (for example the C extensions), profiling should be done on a Linux system, as macOS and Windows do not support the `--native` option of `py-spy`.
474+
Creating an ubuntu Evergreen spawn host and using `scp` to copy the flamegraph `.svg` file back to your local machine is the best way to do this.

0 commit comments

Comments
 (0)