Forrest logo
back to the py-spy tool

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

The command py-spy top --pid ${pid} runs the py-spy tool to collect profiling information about a running Python process with a specific process ID (pid).

Here's what each part of the command means:

  • py-spy: This is the command for running the py-spy tool, which is a sampling profiler for Python that allows you to investigate and analyze the performance of Python code.

  • top: This is an argument for py-spy to specify the profiling mode. In this case, top mode is used, which means it will continuously sample the Python process and display the most active functions in real-time.

  • --pid ${pid}: This is another argument for py-spy to specify the process ID of the Python process you want to profile. ${pid} is a placeholder for the actual process ID, which needs to be replaced with the actual number.

By executing this command, py-spy will attach to the specified Python process and sample its call stack periodically. It will then collect and display information about the most CPU-intensive functions, indicating which functions are taking up the most processing time within the Python process.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the py-spy tool