# git clone --recurse-submodules https://github.com/libbpf/bpftool.git
# cd bpftool/src
# make && make V=1 install
# bpftool version
bpftool v7.0.0
using libbpf v1.0
features: libbpf_strict
bpftool 常见命令
其他命令
// 查看运行的bpf程序
# bpftool prog list
...
//编号 类型 程序名
51544: sched_cls name handle_policy tag 8c2582bd04b4fb9c gpl
loaded_at 2022-06-23T19:25:49+0800 uid 0
xlated 13936B jited 8157B memlock 16384B map_ids 105,107,96,1214,106,101,102,1213,103
btf_id 5906
...
// 支持的bpf程序类型以及对应的help函数
# bpftool feature
# bpftool feature probe
// 把内核已经加载的 prog 程序固定到文件系统
$ bpftool prog pin name hello /sys/fs/bpf/hi
// 查看link列表
$ bpftool link list
// 生成包含所有bpf程序依赖的内核数据结构header文件vmlinux.h
$
// 查看perf相关的程序
$ bpftool perf show
$ bpftool net attach xdp id 540 dev eth0
$ bpftool net list
xdp:
eth0(2) driver id 540
tc:
flow_dissector:
$ ip link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 xdp qdisc
fq_codel state UP
mode DEFAULT group default qlen 1000
...
prog/xdp id 540 tag 9d0e949f89f1a82c jited
git clone https://github.com/iovisor/bcc.git
mkdir bcc/build; cd bcc/build
cmake ..
make
sudo make install
cmake -DPYTHON_CMD=python3 .. # build python3 binding
pushd src/python/
make
sudo make install
popd
编译libbpf-tools
$ git clone https://github.com/iovisor/bcc.git
$ git submodule update --init --recursive
$ cd libbpf-tools
$ make
常见报错:
1、编译过程出现以下报错:
$ make
...
In file included from javagc.bpf.c:6:
In file included from /home/mars/ebpf-demo/bcc/libbpf-tools/.output/bpf/usdt.bpf.h:6:
/usr/include/linux/errno.h:1:10: fatal error: 'asm/errno.h' file not found
#include <asm/errno.h>
^~~~~~~~~~~~~
1 error generated.
make: *** [Makefile:198: /home/mars/ebpf-demo/bcc/libbpf-tools/.output/javagc.bpf.o] Error 1