py-spy
Low-overhead sampling profiler for Python
TLDR
Profile running process
SYNOPSIS
py-spy command [options]
DESCRIPTION
py-spy is a sampling profiler for Python programs that works by reading the process memory of a running Python interpreter without requiring any code modifications or restarts. This approach introduces minimal overhead, making it suitable for profiling production workloads.
The top subcommand provides a live view of where Python is spending time, similar to the Unix top utility. The record subcommand generates flame graphs in SVG, speedscope, or raw format for detailed analysis, and dump captures stack traces from all threads at a single point in time. Written in Rust, py-spy supports CPython interpreters and can attach to already-running processes by PID.
PARAMETERS
top
Live top-like view.record
Record to file.dump
Dump stack traces.--pid PID
Target process ID.-o FILE
Output file.--rate N
Sample rate.
CAVEATS
Requires root for other users' processes. No code modification needed.
HISTORY
py-spy was created for low-overhead Python profiling.
