← 返回命令列表

Linux command

py-spy 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Profile running process

py-spy top --pid [pid]

Record to file

py-spy record -o [profile.svg] --pid [pid]

Dump stacks

py-spy dump --pid [pid]

Profile command

py-spy record -o [output.svg] -- python [script.py]

说明

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.

参数

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.

FAQ

What is the py-spy command used for?

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.

How do I run a basic py-spy example?

Run `py-spy top --pid [pid]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does top do in py-spy?

Live top-like view.