Python debugging tools Py-Spy

Preface

If you are a Python developer transferred from the Java language development, might rejoice in their development efficiency has improved a lot, but there are pain when, for example, you will miss jstack, jmap, and other tools made in a production environment perfomance tuning. I have used before GDB, PyRasite, PyFlameand other tools, especially tools gdb series, Getting Started quite troublesome. Here we recommend a tool: Py-Spy .

Quoted the official description:

Py-Spy program is Python sample analyzer. It allows you to view the Python program to visualize the areas in which to spend more time monitoring the whole way without having to restart the program or modify the project code in any way. Py-Spy's overhead is very low: it is written in Rust, speed and compiled Python program is not running in the same process. This means that the Py-Spy can be safely used Python application tuning analyze production environment generated.

installation

pip install py-spy

Rust If you are a developer, you can also use the following command to install:

cargo install py-spy

use

py-spy program can analyze an existing run (providing PID) or specify the script. as follows:

py-spy --pid 12345
# 或者
py-spy -- python myprogram.py

Output similar to the top command:
py-spy-top

It can also generate output performance optimization master Brandon Greg Release visualized FIG FlameGraphs .
command:

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

Output is as follows:

How Py-Spy works

Py-spy by using process_vm_readv system on the Linux calls, vm_read on OSX call or call ReadProcessMemory memory read data directly python sample analysis program on Windows.

Guess you like

Origin www.cnblogs.com/jcli/p/py-spy.html