一、版本准备
bcc 0.24.0
libbpf 1.0.0
二、依赖项安装
sudo apt-get install bpfcc-tools linux-headers-$(uname -r)
sudo apt-get install bcc-tools libbcc-examples linux-headers-$(uname -r)
sudo apt-get install clang-10 libclang-dev arping netperf iperf
注:按需安装。
三、安装前准备
1.下载bcc
git clone https://github.com/iovisor/bcc.git --branch v0.24.0 --depth 1
2.采用zrait的规避方案,修改bcc/cmake/clang_libs.cmake,相应内容如下:
list(APPEND clang_libs
${libclangParse}
${libclangSema}
${libclangCodeGen}
${libclangAnalysis}
${libclangRewrite}
${libclangEdit}
${libclangAST}
${libclangLex}
${libclangBasic}
Polly
PollyISL)
四、编译安装
cd bcc
git submodule update --init --recursive
mkdir build
cd build/
cmake ..
make -j6
sudo make install
cmake -DPYTHON_CMD=python3 .. # build python3 binding
pushd src/python/
make
sudo make install
popd
五、编译问题
报错1:
could not open bpf map: counts, error: Operation not permitted
Traceback (most recent call last):
File "/usr/share/bcc/tools/filetop", line 164, in <module>
b = BPF(text=bpf_text)
File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 475, in __init__
raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>
root权限或者加sudo
报错2:
Traceback (most recent call last):
File "./cachestat", line 21, in <module>
from bcc import BPF
ImportError:No module named bcc
查看python版本,与当前python版本要一致
ls -l `which python`
# lrwxrwxrwx 1 root root 7 4月 15 2020 /usr/bin/python -> python2
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.8 /usr/bin/python
六、工具测试