因此,我按照此链接将 BPF 程序附加到用户空间探针,Dtrace 格式(请参阅用户静态定义的跟踪点部分)。
C程序:
#include <sys/sdt.h>
int main() {
DTRACE_PROBE("hello-usdt", "probe-main");
}
Run Code Online (Sandbox Code Playgroud)
确保包含探测信息的检查:
readelf -n hello_usdt
stapsdt 0x00000033 NT_STAPSDT (SystemTap probe descriptors)
Provider: "hello_usdt"
Name: "probe-main"
Location: 0x0000000000400535, Base: 0x00000000004005d4, Semaphore: 0x0000000000000000
Arguments:
Run Code Online (Sandbox Code Playgroud)
还有 tplist:
sudo /usr/share/bcc/tools/tplist -l /path/to/hello_usdt
/path/to/hello_usdt "hello_usdt":"probe-main"
Run Code Online (Sandbox Code Playgroud)
BPF程序的内容(usdt.py):
readelf -n hello_usdt
stapsdt 0x00000033 NT_STAPSDT (SystemTap probe descriptors)
Provider: "hello_usdt"
Name: "probe-main"
Location: 0x0000000000400535, Base: 0x00000000004005d4, Semaphore: 0x0000000000000000
Arguments:
Run Code Online (Sandbox Code Playgroud)
故障描述:
sudo ./usdt.py
Traceback (most recent call last):
File "./usdt.py", line 13, in <module>
usdt.enable_probe(probe …Run Code Online (Sandbox Code Playgroud)