Sampling profiler for Python programs
open sourceMITself-hostablefree
py-spy is a sampling profiler that shows what a Python program is spending time on without restarting it or modifying its code. It runs outside the profiled process and is written in Rust for low overhead, so it is safe to attach to production. It can record flame graphs, show a live top-like view, or dump current stack traces, and supports CPython 2.3-2.7 and 3.3-3.15 on Linux, macOS, Windows and FreeBSD.
Ways to install
Package managers
Problems it solves
- my Python service in production is slow and I cannot add profiling code
- attach a profiler to an already running Python process by PID
- see a flame graph of where my Python script spends time
- my Python process is stuck, show me what every thread is doing
- cProfile overhead distorts the results
- top-like live view of the hottest Python functions
- profile a Python job inside a Docker container
- find which function is burning CPU in a Django worker
Features
- attach by PID
- record flame graphs
- top view
- dump stack traces
- low overhead, out of process
Capabilities
| Has a command line tool | plan not known |
|---|
Alternatives
The same job
These do what py-spy does.
- hyperfine A command-line benchmarking tool
