py-spy

Open Source

by py-spy

Provided by py-spy

Not yet rated
Platform
Windows / Linux / macOS
Pricing
Open Source
Account required
No
Ads
None
Last verified
9 hours ago
Developer
py-spy
Official URL

Overview

py-spy is a sampling profiler for Python programs. It shows where a program is spending its time without you having to restart it or change a line of its code. It is written in Rust and runs as a separate process that reads the target's memory from outside, which keeps the overhead low enough that the project describes it as suitable for use on production code.

There are three commands. record samples a program for a while and writes a profile, by default an interactive SVG flame graph, with speedscope and raw formats also available. top gives a live, continuously refreshing view of the functions using the most time, much like the Unix top command. dump prints the current call stack of every Python thread, optionally with local variables, which is handy when a program appears to be stuck.

It is aimed at Python developers and operations people who need to diagnose a slow or hung process, including one that is already running. The main hurdle is permissions: reading another process's memory needs root on macOS and often sudo on Linux, and containers need the SYS_PTRACE capability.

Features

  • Samples a running Python process without code changes or a restart
  • record command writes interactive SVG flame graphs
  • Speedscope and raw output formats for other viewers
  • top command shows a live list of the busiest functions
  • dump command prints every thread's call stack, optionally with local variables
  • Option to include native C, C++ or Cython frames on supported platforms
  • Can follow subprocesses and show only threads holding the GIL
  • Installs with pip, cargo, Homebrew or prebuilt binaries

Privacy

See the official privacy policy. py-spy is a command-line program that runs on your own machine and writes its profiles to local files or the terminal.

Pros & Cons

Pros

  • Attaches to a process that is already running, by process ID
  • Runs outside the profiled program, so overhead is low
  • Supports a very wide range of CPython versions, from 2.3 up to current 3.x
  • MIT licensed and free
  • Works on Linux, macOS, Windows and FreeBSD

Cons

  • Needs root on macOS and usually sudo on Linux to attach to an existing process
  • Docker and Kubernetes need the SYS_PTRACE capability added
  • PyPy and 32-bit Windows are not supported
  • Native-extension profiling is limited to certain platforms, mainly Linux

Community Reviews (0)

No written reviews yet — be the first to rate this tool.

Similar Tools

  • Profilers · Blackfire

    Profiles and monitors the performance of PHP and Python applications.

    Not yet rated
    Paid Web
  • Profilers · Xdebug

    Profiles PHP code to find performance bottlenecks.

    Not yet rated
    Open Source Web