Skip to content
/ py-spy Public
forked from benfred/py-spy

Sampling profiler for Python programs

Notifications You must be signed in to change notification settings

jonntd/py-spy

 
 

Repository files navigation

Py-Spy: A sampling profiler for Python programs.

Build Status Windows Build status

Py-Spy is a sampling profiler for Python programs. It lets you visualize what your Python program is spending time on without restarting the program or modifiying the code in any way. Py-Spy is extremely low overhead: it is written in Rust for speed and doesn't pause or slow down the profiled Python program. This means Py-Spy is safe to use in production.

Py-Spy works on Linux, OSX and Windows, and supports profiling all recent versions of the CPython interpreter (versions 2.3-2.7 and 3.3-3.7).

Installation

Prebuilt binary wheels can be installed from PyPI with:

pip install py-spy

Usage

py-spy works from the command line and takes either the PID of the program you want to sample from, or the command line of the python program you want to run:

py-spy --pid 12345
# OR
py-spy -- python myprogram.py

The default visualization is a top-like live view of your python program:

console viewer demo

There is also support for generating flame graphs from the running process:

py-spy --flame profile.svg --pid 12345
# OR
py-spy --flame profile.svg -- python myprogram.py

Which will generate a SVG file looking like:

flame graph

Credits

py-spy is heavily inspired by Julia Evans excellent work on rbspy. In particular the code to generate the flamegraphs is taken directly from rbspy, and this project use several crates (read-process-memory and proc-maps) that were spun off from rbspy.

About

Sampling profiler for Python programs

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 95.5%
  • Python 4.4%
  • Other 0.1%