Forrest logo
tool overview
On this page you find all important commands for the CLI tool py-spy. If the command you are looking for is missing please ask our AI.


Py-spy is a powerful command line tool used for profiling Python applications. It allows developers to analyze the performance of their programs by sampling the execution stack to identify bottlenecks and areas of improvement.

  1. It is written in Rust and can be easily installed using package managers like Homebrew or by directly downloading pre-built binaries.
  2. Py-spy supports profiling both CPU-bound and memory-bound applications, providing insights into how much time is spent on different functions.
  3. It uses the Linux perf_events subsystem for CPU profiling, making it highly efficient and accurate.
  4. Being a sampling profiler, it avoids the need for instrumentation or modifying the code, making it convenient for profiling third-party libraries or closed-source applications.
  5. Py-spy supports navigating the profile data using the Flamegraph format, which represents the call stack as a flame-like visualization.
  6. It can be integrated with other tools like web browsers or Jupyter notebooks to provide a more detailed analysis of the profiled data.
  7. Py-spy offers different sampling modes, allowing users to choose the sampling frequency according to their specific requirements.
  8. It can generate detailed reports with information on the number of samples, CPU time, memory usage, and more for each function.
  9. Py-spy has minimal overhead, ensuring that the profiling process does not significantly impact the performance of the profiled application.
  10. It is compatible with both Python 2.x and Python 3.x, making it suitable for a wide range of Python projects.

List of commands for py-spy:

  • py-spy:tldr:01d9d py-spy: Show a live view of the functions that take the most execution time of a running process.
    $ py-spy top --pid ${pid}
    try on your machine
    explain this command
  • py-spy:tldr:4af81 py-spy: Dump the call stack of a running process.
    $ py-spy dump --pid ${pid}
    try on your machine
    explain this command
  • py-spy:tldr:83d59 py-spy: Produce an SVG flame graph of the function call execution time.
    $ py-spy record -o ${path-to-profile-svg} --pid ${pid}
    try on your machine
    explain this command
tool overview