Search code examples
pythonlinuxebpfbpfbcc

Python dtrace + bpftrace


I built Python 3.12 with dtrace support and python:function__entry is not properly called.

python:line probe works well, but python:function__entry rarely prints things.

❯ sudo bpftrace -e 'usdt:/usr/lib/libpython3.12.so.1.0:python:line { printf("%s %s %d\n", str(arg0), str(arg1), arg2); }'
❯ sudo bpftrace -e 'usdt:/usr/lib/libpython3.12.so.1.0:python:function__entry { printf("%s %s\n", str(arg0), str(arg1)); }'

❯ python3.12 -m http.server
Attaching 1 probe...
<frozen getpath> <genexpr>
<frozen getpath> <genexpr>
/usr/lib/python3.12/enum.py <genexpr>
/usr/lib/python3.12/enum.py <genexpr>
/usr/lib/python3.12/enum.py <genexpr>
/usr/lib/python3.12/enum.py <genexpr>
/usr/lib/python3.12/email/_policybase.py <genexpr>
/usr/lib/python3.12/email/_policybase.py <genexpr>
/usr/lib/python3.12/email/_policybase.py <genexpr>
/usr/lib/python3.12/email/_policybase.py <genexpr>
/usr/lib/python3.12/email/_policybase.py <genexpr>

Also bcc's ustats and ucalls attach but report nothing.

PID    CMDLINE              METHOD/s   GC/s   OBJNEW/s   CLOAD/s  EXC/s  THR/s 
6857   /bin/python /home/xx 0          0      0          0        0      0 

I expected it to print every python function call. Why is it skipping most calls?


Solution

  • This is a bug since Python 3.11.

    https://github.com/python/cpython/issues/98894