beetrace allows you to trace a Python process line by line or the functions’ entries
and returns. It uses USDT(User Statically-Defined Tracing) probes with
bpftrace.
Dependencies
This package is only available for Linux and requires bpftrace. You can look at the
bpftrace installation
here.CPython must be
configured with the –with-dtrace option.
Installation
Usage & Example
To trace the Python process, use the -p parameter to pass the pid value.
beetrace -p {pid of process}Let’s take a look at the quick example.
$ cat -n example.py 1 import os 2 from time import sleep 3 4 5 def c(): 6 x = 1 7 8 def b(): 9 y = 2 10 c() 11 12 13 def a(): 14 z = 1 15 b() 16 17 18 while True: 19 print(f"PID of program: {os.getpid()}") 20 sleep(1) 21 print("Sleep 1 second") 22 a()
Output:
PID of program: 17988 Sleep 1 second PID of program: 17988 Sleep 1 second PID of program: 17988 Sleep 1 second PID of program: 17988 ... ... ...
beetrace.mp4
Read More
Nancie Pecora

