bcc安装过程以及遇到的问题

二进制安装

对于5.15版本的安装

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4052245BD4284CDD
Executing: /tmp/apt-key-gpghome.yKCApS0t8A/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 4052245BD4284CDD
gpg: 密钥 4052245BD4284CDD:公钥 “Brenden Blanco <bblanco@plumgrid.com>” 已导入
gpg: 处理的总数:1
gpg:               已导入:1
$ echo "deb https://repo.iovisor.org/apt/xenial xenial main" | sudo tee /etc/apt/sources.list.d/iovisor.list
deb https://repo.iovisor.org/apt/xenial xenial main
$ sudo apt-get update
命中:1 http://packages.microsoft.com/repos/code stable InRelease
命中:2 http://dl.google.com/linux/chrome/deb stable InRelease                                                                                                                                            
命中:3 http://security.ubuntu.com/ubuntu focal-security InRelease                                                                                                                                        
命中:4 http://cn.archive.ubuntu.com/ubuntu focal InRelease                                                                               
命中:5 http://cn.archive.ubuntu.com/ubuntu focal-updates InRelease                                                                    
命中:6 http://cn.archive.ubuntu.com/ubuntu focal-backports InRelease                                                                  
获取:7 https://repo.iovisor.org/apt/xenial xenial InRelease [2,419 B]                                                                 
命中:8 http://lenovo.archive.canonical.com focal InRelease                                        
获取:9 https://repo.iovisor.org/apt/xenial xenial/main i386 Packages [1,062 B]
获取:10 https://repo.iovisor.org/apt/xenial xenial/main amd64 Packages [1,197 B]
已下载 2,259 B,耗时 2秒 (1,050 B/s)   
正在读取软件包列表... 完成
$ sudo apt-get install -y bcc-tools libbcc-examples linux-headers-$(uname -r)
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
linux-headers-5.15.0-46-generic 已经是最新版 (5.15.0-46.49~20.04.1)。
linux-headers-5.15.0-46-generic 已设置为手动安装。
将会同时安装下列软件:
  libbcc python-bcc
下列【新】软件包将被安装:
  bcc-tools libbcc libbcc-examples python-bcc
升级了 0 个软件包,新安装了 4 个软件包,要卸载 0 个软件包,有 29 个软件包未被升级。
需要下载 12.6 MB 的归档。
解压缩后会消耗 45.2 MB 的额外空间。
获取:1 https://repo.iovisor.org/apt/xenial xenial/main amd64 libbcc all 0.10.0-1 [11.9 MB]
获取:2 https://repo.iovisor.org/apt/xenial xenial/main amd64 python-bcc all 0.10.0-1 [30.8 kB]                                                                                                                    
获取:3 https://repo.iovisor.org/apt/xenial xenial/main amd64 bcc-tools all 0.10.0-1 [356 kB]                                                                                                                      
获取:4 https://repo.iovisor.org/apt/xenial xenial/main amd64 libbcc-examples amd64 0.10.0-1 [278 kB]                                                                                                              
已下载 12.6 MB,耗时 4分 15秒 (49.3 kB/s)                                                                                                                                                                         
正在选中未选择的软件包 libbcc。
(正在读取数据库 ... 系统当前共安装有 279008 个文件和目录。)
准备解压 .../libbcc_0.10.0-1_all.deb  ...
正在解压 libbcc (0.10.0-1) ...
正在选中未选择的软件包 python-bcc。
准备解压 .../python-bcc_0.10.0-1_all.deb  ...
正在解压 python-bcc (0.10.0-1) ...
正在选中未选择的软件包 bcc-tools。
准备解压 .../bcc-tools_0.10.0-1_all.deb  ...
正在解压 bcc-tools (0.10.0-1) ...
正在选中未选择的软件包 libbcc-examples。
准备解压 .../libbcc-examples_0.10.0-1_amd64.deb  ...
正在解压 libbcc-examples (0.10.0-1) ...
正在设置 libbcc (0.10.0-1) ...
正在设置 python-bcc (0.10.0-1) ...
正在设置 libbcc-examples (0.10.0-1) ...
正在设置 bcc-tools (0.10.0-1) ...
正在处理用于 libc-bin (2.31-0ubuntu9.9) 的触发器 ...
$ bcc

Command 'bcc' not found, but can be installed with:

sudo apt install bcc

$ cachestat

Command 'cachestat' not found, did you mean:

  command 'cachestats' from deb nocache (1.1-1)

Try: sudo apt install <deb name>

$ export PATH=$PATH:/usr/share/bcc/tools
$ cachestat
Traceback (most recent call last):
  File "/usr/share/bcc/tools/cachestat", line 21, in <module>
    from bcc import BPF
  File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 27, in <module>
    from .libbcc import lib, bcc_symbol, bcc_symbol_option, bcc_stacktrace_build_id, _SYM_CB_TYPE
  File "/usr/lib/python2.7/dist-packages/bcc/libbcc.py", line 17, in <module>
    lib = ct.CDLL("libbcc.so.0", use_errno=True)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 366, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libtinfo.so.5: cannot open shared object file: No such file or directory
$ sudo -i
~# export PATH=$PATH:/usr/share/bcc/tools
~# cachestat
Traceback (most recent call last):
  File "/usr/share/bcc/tools/cachestat", line 21, in <module>
    from bcc import BPF
  File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 27, in <module>
    from .libbcc import lib, bcc_symbol, bcc_symbol_option, bcc_stacktrace_build_id, _SYM_CB_TYPE
  File "/usr/lib/python2.7/dist-packages/bcc/libbcc.py", line 17, in <module>
    lib = ct.CDLL("libbcc.so.0", use_errno=True)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 366, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libtinfo.so.5: cannot open shared object file: No such file or directory
~# cat /boot/
config-5.15.0-41-generic      grub/                         initrd.img-5.15.0-46-generic  memtest86+.elf                System.map-5.15.0-46-generic  vmlinuz-5.15.0-46-generic     
config-5.15.0-46-generic      initrd.img                    initrd.img.old                memtest86+_multiboot.bin      vmlinuz                       vmlinuz.old                   
efi/                          initrd.img-5.15.0-41-generic  memtest86+.bin                System.map-5.15.0-41-generic  vmlinuz-5.15.0-41-generic     
~# cat /boot/config-5.15.0-46-generic | grep BPF
CONFIG_BPF=y
CONFIG_HAVE_EBPF_JIT=y
CONFIG_ARCH_WANT_DEFAULT_BPF_JIT=y
# BPF subsystem
CONFIG_BPF_SYSCALL=y
CONFIG_BPF_JIT=y
CONFIG_BPF_JIT_ALWAYS_ON=y
CONFIG_BPF_JIT_DEFAULT_ON=y
CONFIG_BPF_UNPRIV_DEFAULT_OFF=y
# CONFIG_BPF_PRELOAD is not set
CONFIG_BPF_LSM=y
# end of BPF subsystem
CONFIG_CGROUP_BPF=y
CONFIG_IPV6_SEG6_BPF=y
CONFIG_NETFILTER_XT_MATCH_BPF=m
CONFIG_BPFILTER=y
CONFIG_BPFILTER_UMH=m
CONFIG_NET_CLS_BPF=m
CONFIG_NET_ACT_BPF=m
CONFIG_BPF_STREAM_PARSER=y
CONFIG_LWTUNNEL_BPF=y
CONFIG_BPF_EVENTS=y
CONFIG_BPF_KPROBE_OVERRIDE=y
CONFIG_TEST_BPF=m
~# cachestat 1 3
Traceback (most recent call last):
  File "/usr/share/bcc/tools/cachestat", line 21, in <module>
    from bcc import BPF
  File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 27, in <module>
    from .libbcc import lib, bcc_symbol, bcc_symbol_option, bcc_stacktrace_build_id, _SYM_CB_TYPE
  File "/usr/lib/python2.7/dist-packages/bcc/libbcc.py", line 17, in <module>
    lib = ct.CDLL("libbcc.so.0", use_errno=True)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 366, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libtinfo.so.5: cannot open shared object file: No such file or directory
~# 

解决方法

~# ls /usr/libtinfo*
ls: 无法访问 '/usr/libtinfo*': 没有那个文件或目录
~# exit
注销
$ sudo apt-get install libncurses5
 
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
将会同时安装下列软件:
  libtinfo5
下列【新】软件包将被安装:
  libncurses5 libtinfo5
升级了 0 个软件包,新安装了 2 个软件包,要卸载 0 个软件包,有 29 个软件包未被升级。
需要下载 180 kB 的归档。
解压缩后会消耗 864 kB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://cn.archive.ubuntu.com/ubuntu focal/universe amd64 libtinfo5 amd64 6.2-0ubuntu2 [83.0 kB]
获取:2 http://cn.archive.ubuntu.com/ubuntu focal/universe amd64 libncurses5 amd64 6.2-0ubuntu2 [96.9 kB]
已下载 180 kB,耗时 1秒 (123 kB/s)    
正在选中未选择的软件包 libtinfo5:amd64。
(正在读取数据库 ... 系统当前共安装有 279539 个文件和目录。)
准备解压 .../libtinfo5_6.2-0ubuntu2_amd64.deb  ...
正在解压 libtinfo5:amd64 (6.2-0ubuntu2) ...
正在选中未选择的软件包 libncurses5:amd64。
准备解压 .../libncurses5_6.2-0ubuntu2_amd64.deb  ...
正在解压 libncurses5:amd64 (6.2-0ubuntu2) ...
正在设置 libtinfo5:amd64 (6.2-0ubuntu2) ...
正在设置 libncurses5:amd64 (6.2-0ubuntu2) ...
正在处理用于 libc-bin (2.31-0ubuntu9.9) 的触发器 ...
$ cachestat
In file included from <built-in>:317:
In file included from <command line>:7:
In file included from /virtual/include/bcc/bpf.h:12:
In file included from include/linux/types.h:6:
In file included from include/uapi/linux/types.h:14:
In file included from ./include/uapi/linux/posix_types.h:5:
In file included from include/linux/stddef.h:5:
In file included from include/uapi/linux/stddef.h:2:
In file included from include/linux/compiler_types.h:80:
include/linux/compiler-clang.h:41:9: warning: '__HAVE_BUILTIN_BSWAP32__' macro redefined [-Wmacro-redefined]
#define __HAVE_BUILTIN_BSWAP32__
        ^
<command line>:4:9: note: previous definition is here
#define __HAVE_BUILTIN_BSWAP32__ 1
        ^
In file included from <built-in>:317:
In file included from <command line>:7:
In file included from /virtual/include/bcc/bpf.h:12:
In file included from include/linux/types.h:6:
In file included from include/uapi/linux/types.h:14:
In file included from ./include/uapi/linux/posix_types.h:5:
In file included from include/linux/stddef.h:5:
In file included from include/uapi/linux/stddef.h:2:
In file included from include/linux/compiler_types.h:80:
include/linux/compiler-clang.h:42:9: warning: '__HAVE_BUILTIN_BSWAP64__' macro redefined [-Wmacro-redefined]
#define __HAVE_BUILTIN_BSWAP64__
        ^
<command line>:5:9: note: previous definition is here
#define __HAVE_BUILTIN_BSWAP64__ 1
        ^
In file included from <built-in>:317:
In file included from <command line>:7:
In file included from /virtual/include/bcc/bpf.h:12:
In file included from include/linux/types.h:6:
In file included from include/uapi/linux/types.h:14:
In file included from ./include/uapi/linux/posix_types.h:5:
In file included from include/linux/stddef.h:5:
In file included from include/uapi/linux/stddef.h:2:
In file included from include/linux/compiler_types.h:80:
include/linux/compiler-clang.h:43:9: warning: '__HAVE_BUILTIN_BSWAP16__' macro redefined [-Wmacro-redefined]
#define __HAVE_BUILTIN_BSWAP16__
        ^
<command line>:3:9: note: previous definition is here
#define __HAVE_BUILTIN_BSWAP16__ 1
        ^
In file included from /virtual/main.c:2:
In file included from include/uapi/linux/ptrace.h:153:
In file included from ./arch/x86/include/asm/ptrace.h:5:
./arch/x86/include/asm/segment.h:255:2: error: expected '(' after 'asm'
        alternative_io ("lsl %[seg],%[p]",
        ^
./arch/x86/include/asm/alternative.h:248:2: note: expanded from macro 'alternative_io'
        asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, feature)   \
        ^
include/linux/compiler_types.h:258:24: note: expanded from macro 'asm_inline'
#define asm_inline asm __inline
                       ^
3 warnings and 1 error generated.
Traceback (most recent call last):
  File "/usr/share/bcc/tools/cachestat", line 96, in <module>
    b = BPF(text=bpf_text)
  File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 325, in __init__
    raise Exception("Failed to compile BPF text")
Exception: Failed to compile BPF text

对于4.19版本的安装

rlk@ubuntu:~$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4052245BD4284CDD
[sudo] password for rlk: 
Executing: /tmp/apt-key-gpghome.mIpNWGNyeE/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 4052245BD4284CDD
gpg: key 4052245BD4284CDD: "Brenden Blanco <bblanco@plumgrid.com>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1
rlk@ubuntu:~$ cat /etc/apt/sources.list.d/iovisor.list
deb https://repo.iovisor.org/apt/xenial xenial main
rlk@ubuntu:~$ 
rlk@ubuntu:~$ sudo apt-get update
Hit:1 http://mirrors.cn99.com/ubuntu bionic InRelease
Hit:2 http://mirrors.cn99.com/ubuntu bionic-updates InRelease                                                    
Hit:3 http://mirrors.cn99.com/ubuntu bionic-backports InRelease                                                  
Hit:4 http://mirrors.cn99.com/ubuntu bionic-security InRelease                                                   
Ign:5 https://repo.iovisor.org/apt/xenial xenial InRelease                                                       
Err:6 https://repo.iovisor.org/apt/xenial xenial Release                                                         
  Certificate verification failed: The certificate is NOT trusted. The certificate chain uses expired certificate.  Could not handshake: Error in the certificate verification. [IP: 104.199.116.191 443]
Err:7 http://archive.ubuntukylin.com:10006/ubuntukylin xenial InRelease                                       
  Could not connect to archive.ubuntukylin.com:10006 (124.126.103.228). - connect (111: Connection refused)
Err:8 http://archive.ubuntukylin.com:10006/ubuntukylin bionic InRelease
  Unable to connect to archive.ubuntukylin.com:10006:
Reading package lists... Done
E: The repository 'https://repo.iovisor.org/apt/xenial xenial Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

解决方法

将 https://repo.iovisor.org/apt/xenial xenial InRelease的https 修改为 http

去掉 http://archive.ubuntukylin.com:10006/ubuntukylin

再来一遍

root@ubuntu:apt# apt update
Hit:1 http://mirrors.cn99.com/ubuntu bionic InRelease
Hit:2 http://mirrors.cn99.com/ubuntu bionic-updates InRelease
Hit:3 http://mirrors.cn99.com/ubuntu bionic-backports InRelease
Hit:4 http://mirrors.cn99.com/ubuntu bionic-security InRelease
Hit:5 http://repo.iovisor.org/apt/xenial xenial InRelease                       
Reading package lists... Done                      
Building dependency tree       
Reading state information... Done
723 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@ubuntu:apt#  apt-get install -y bcc-tools libbcc-examples
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libbcc python-bcc
The following NEW packages will be installed:
  bcc-tools libbcc libbcc-examples python-bcc
0 upgraded, 4 newly installed, 0 to remove and 723 not upgraded.
Need to get 12.6 MB of archives.
After this operation, 45.2 MB of additional disk space will be used.
Get:1 http://repo.iovisor.org/apt/xenial xenial/main amd64 libbcc all 0.10.0-1 [11.9 MB]
Get:2 http://repo.iovisor.org/apt/xenial xenial/main amd64 python-bcc all 0.10.0-1 [30.8 kB]                     
Get:3 http://repo.iovisor.org/apt/xenial xenial/main amd64 bcc-tools all 0.10.0-1 [356 kB]                       
Get:4 http://repo.iovisor.org/apt/xenial xenial/main amd64 libbcc-examples amd64 0.10.0-1 [278 kB]               
Fetched 12.6 MB in 32s (398 kB/s)                                                                                
Selecting previously unselected package libbcc.
(Reading database ... 275684 files and directories currently installed.)
Preparing to unpack .../libbcc_0.10.0-1_all.deb ...
Unpacking libbcc (0.10.0-1) ...
Selecting previously unselected package python-bcc.
Preparing to unpack .../python-bcc_0.10.0-1_all.deb ...
Unpacking python-bcc (0.10.0-1) ...
Selecting previously unselected package bcc-tools.
Preparing to unpack .../bcc-tools_0.10.0-1_all.deb ...
Unpacking bcc-tools (0.10.0-1) ...
Selecting previously unselected package libbcc-examples.
Preparing to unpack .../libbcc-examples_0.10.0-1_amd64.deb ...
Unpacking libbcc-examples (0.10.0-1) ...
Setting up libbcc (0.10.0-1) ...
Setting up python-bcc (0.10.0-1) ...
Setting up bcc-tools (0.10.0-1) ...
Setting up libbcc-examples (0.10.0-1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...

4.19版本也遇到如下问题的话

rlk@ubuntu:~$ /usr/share/bcc/tools/cachestat
Traceback (most recent call last):
  File "/usr/share/bcc/tools/cachestat", line 21, in <module>
    from bcc import BPF
ImportError: No module named bcc

解决方法

root@ubuntu:apt# uname -a
Linux ubuntu 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
root@ubuntu:apt#

rlk@ubuntu:~$ ls /usr/src/
linux-headers-4.15.0-29  linux-headers-4.15.0-29-generic
rlk@ubuntu:~$ ls /usr/src/ -l
total 8
drwxr-xr-x 27 root root 4096 Jul 24  2018 linux-headers-4.15.0-29
drwxr-xr-x  8 root root 4096 Jul 24  2018 linux-headers-4.15.0-29-generic
rlk@ubuntu:~$ uname -a
Linux ubuntu 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
rlk@ubuntu:~$ sudo -i
root@ubuntu:~# mkdir /usr/src/kernel
root@ubuntu:~# mkdir /usr/src/kernels
root@ubuntu:~# rm -rf /usr/src/kernel
root@ubuntu:~# ln -s /usr/src/linux-headers-4.15.0-29-generic /usr/src/kernels/linux-headers-4.15.0-29-generic
root@ubuntu:~# ls /usr/src/kernels/
linux-headers-4.15.0-29-generic
root@ubuntu:~# /usr/share/bcc/tools/cachestat

开始运行

root@ubuntu:apt# usr/share/bcc/tools/cachestat
-bash: usr/share/bcc/tools/cachestat: No such file or directory
root@ubuntu:apt# /usr/share/bcc/tools/cachestat
    HITS   MISSES  DIRTIES HITRATIO   BUFFERS_MB  CACHED_MB
   11632        0      837  100.00%           56       1148
    4549        0      809  100.00%           56       1148
   46702        0        5  100.00%           56       1148
       3        0        0  100.00%           56       1148
       0        0        8    0.00%           56       1148
       3        0        0  100.00%           56       1148
       3        0        0  100.00%           56       1148
       3        0        0  100.00%           56       1148
       3        0        0  100.00%           56       1148

源代码安装

安装依赖

user@Ubuntu:~$ sudo apt install -y bison build-essential cmake flex git libedit-dev \
  libllvm11 llvm-11-dev libclang-11-dev python3-distutils zlib1g-dev libelf-dev libfl-dev python3-setuptools

克隆和配置 bcc 过程中需要克隆 一些依赖的子仓,注意国内 github 下载不稳定,需要耐心

user@Ubuntu:~$ git clone https://github.com/iovisor/bcc.git
Cloning into 'bcc'...
remote: Enumerating objects: 30458, done.
remote: Counting objects: 100% (108/108), done.
remote: Compressing objects: 100% (79/79), done.
remote: Total 30458 (delta 52), reused 30 (delta 29), pack-reused 30350 (from 3)
Receiving objects: 100% (30458/30458), 23.28 MiB | 30.00 KiB/s, done.
Resolving deltas: 100% (20218/20218), done.

# 
user@Ubuntu:~$ cd bcc
user@Ubuntu:~/bcc$ mkdir build && cd build

user@Ubuntu:~/bcc/build$ cmake ..
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Submodule 'libbpf-tools/blazesym' (https://github.com/libbpf/blazesym) registered for path 'libbpf-tools/blazesym'
Cloning into '/home/user/bcc/libbpf-tools/blazesym'...
Submodule path 'libbpf-tools/blazesym': checked out 'd954f73867527dc75025802160c759d0b6a0641f'
Submodule 'libbpf-tools/bpftool' (https://github.com/libbpf/bpftool) registered for path 'libbpf-tools/bpftool'
Submodule 'src/cc/libbpf' (https://github.com/libbpf/libbpf.git) registered for path 'src/cc/libbpf'
Cloning into '/home/user/bcc/libbpf-tools/bpftool'...
error: RPC failed; curl 56 GnuTLS recv error (-54): Error in the pull function.
error: 5474 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
fatal: clone of 'https://github.com/libbpf/bpftool' into submodule path '/home/user/bcc/libbpf-tools/bpftool' failed
Failed to clone 'libbpf-tools/bpftool'. Retry scheduled
Cloning into '/home/user/bcc/src/cc/libbpf'...
error: RPC failed; curl 16 Error in the HTTP2 framing layer
fatal: expected flush after ref listing
fatal: clone of 'https://github.com/libbpf/libbpf.git' into submodule path '/home/user/bcc/src/cc/libbpf' failed
Failed to clone 'src/cc/libbpf'. Retry scheduled
Cloning into '/home/user/bcc/libbpf-tools/bpftool'...
error: RPC failed; curl 16 Error in the HTTP2 framing layer
fatal: expected flush after ref listing
fatal: clone of 'https://github.com/libbpf/bpftool' into submodule path '/home/user/bcc/libbpf-tools/bpftool' failed
Failed to clone 'libbpf-tools/bpftool' a second time, aborting
CMake Warning at CMakeLists.txt:66 (message):
  Failed to update submodule libbpf


-- Latest recognized Git tag is v0.35.0
-- Git HEAD is 9691c56891fb833351d3cfe69bda4a57076c3b62
-- Revision is 0.35.0+9691c568 (major 0, minor 35, patch 0)
-- Performing Test HAVE_NO_PIE_FLAG
-- Performing Test HAVE_NO_PIE_FLAG - Success
-- Performing Test HAVE_REALLOCARRAY_SUPPORT
-- Performing Test HAVE_REALLOCARRAY_SUPPORT - Success
-- Kernel release: 6.6.63-linux
-- Kernel headers: /usr/src/linux-headers-6.6.63-linux
-- Found LLVM: /usr/lib/llvm-11/include 11.1.0 (Use LLVM_ROOT envronment variable for another version of LLVM)
-- Found BISON: /usr/bin/bison (found version "3.8.2") 
-- Found FLEX: /usr/bin/flex (found version "2.6.4") 
-- Found LibElf: /usr/lib/aarch64-linux-gnu/libelf.so  
-- Performing Test ELF_GETSHDRSTRNDX
-- Performing Test ELF_GETSHDRSTRNDX - Success
-- Could NOT find LibDebuginfod (missing: LIBDEBUGINFOD_LIBRARIES LIBDEBUGINFOD_INCLUDE_DIRS) 
-- Found LibLzma: /usr/lib/aarch64-linux-gnu/liblzma.so  
-- Using static-libstdc++
-- Could NOT find LuaJIT (missing: LUAJIT_LIBRARIES LUAJIT_INCLUDE_DIR) 
CMake Warning at tests/python/CMakeLists.txt:6 (message):
  Recommended test program 'arping' not found


CMake Warning at tests/python/CMakeLists.txt:10 (message):
  Recommended test program 'netperf' not found


CMake Warning at tests/python/CMakeLists.txt:16 (message):
  Recommended test program 'iperf' or 'iperf3' not found


-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/bcc/build
user@Ubuntu:~/bcc/build$ echo $?
0

开始编译

user@Ubuntu:~/bcc/build$ make
[  0%] Building CXX object src/cc/frontends/clang/CMakeFiles/clang_frontend-objects.dir/loader.cc.o
In file included from /usr/lib/llvm-11/include/clang/AST/RecursiveASTVisitor.h:23,
                 from /home/user/bcc/src/cc/frontends/clang/b_frontend_action.h:23,
                 from /home/user/bcc/src/cc/frontends/clang/loader.cc:57:
/usr/lib/llvm-11/include/clang/AST/DeclOpenMP.h:97:1: warning: multi-line comment [-Wcomment]
   97 | /// #pragma omp declare reduction (foo : int,float : omp_out += omp_in) \
      | ^
In file included from /usr/lib/llvm-11/include/clang/AST/RecursiveASTVisitor.h:16,
                 from /home/user/bcc/src/cc/frontends/clang/b_frontend_action.h:23,
                 from /home/user/bcc/src/cc/frontends/clang/loader.cc:57:
/usr/lib/llvm-11/include/clang/AST/Attr.h: In static member function ‘static clang::ParamIdx clang::ParamIdx::deserialize(clang::ParamIdx::SerialType)’:
/usr/lib/llvm-11/include/clang/AST/Attr.h:262:17: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  262 |     ParamIdx P(*reinterpret_cast<ParamIdx *>(&S));
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/llvm-11/include/clang/AST/Attr.h:262:17: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[  1%] Building CXX object src/cc/frontends/clang/CMakeFiles/clang_frontend-objects.dir/b_frontend_action.cc.o
In file included from /usr/lib/llvm-11/include/clang/AST/RecursiveASTVisitor.h:23,
                 from /home/user/bcc/src/cc/frontends/clang/b_frontend_action.h:23,
                 from /home/user/bcc/src/cc/frontends/clang/b_frontend_action.cc:31:
/usr/lib/llvm-11/include/clang/AST/DeclOpenMP.h:97:1: warning: multi-line comment [-Wcomment]
   97 | /// #pragma omp declare reduction (foo : int,float : omp_out += omp_in) \
      | ^
In file included from /home/user/bcc/src/cc/frontends/clang/b_frontend_action.cc:37:
/home/user/bcc/src/cc/bcc_libbpf_inc.h:8:11: fatal error: libbpf/src/bpf.h: No such file or directory
    8 | # include "libbpf/src/bpf.h"
      |           ^~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [src/cc/frontends/clang/CMakeFiles/clang_frontend-objects.dir/build.make:90: src/cc/frontends/clang/CMakeFiles/clang_frontend-objects.dir/b_frontend_action.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:968: src/cc/frontends/clang/CMakeFiles/clang_frontend-objects.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

编译报错 因为缺少 libbpf 依赖, 其实在前面的 克隆和配置阶段已经有提示了,重来吧

user@Ubuntu:~/bcc/build$ cmake ..
Cloning into '/home/user/bcc/libbpf-tools/bpftool'...
fatal: unable to access 'https://github.com/libbpf/bpftool/': Failed to connect to github.com port 443 after 134962 ms: Connection timed out
fatal: clone of 'https://github.com/libbpf/bpftool' into submodule path '/home/user/bcc/libbpf-tools/bpftool' failed
Failed to clone 'libbpf-tools/bpftool'. Retry scheduled
Cloning into '/home/user/bcc/src/cc/libbpf'...
fatal: unable to access 'https://github.com/libbpf/libbpf.git/': Failed to connect to github.com port 443 after 135138 ms: Connection timed out
fatal: clone of 'https://github.com/libbpf/libbpf.git' into submodule path '/home/user/bcc/src/cc/libbpf' failed
Failed to clone 'src/cc/libbpf'. Retry scheduled
Cloning into '/home/user/bcc/libbpf-tools/bpftool'...
Cloning into '/home/user/bcc/src/cc/libbpf'...
Submodule path 'libbpf-tools/bpftool': checked out '6eb3e20583da834da18ea3011dcefd08b3493f8d'
Submodule 'libbpf' (https://github.com/libbpf/libbpf.git) registered for path 'libbpf-tools/bpftool/libbpf'
Cloning into '/home/user/bcc/libbpf-tools/bpftool/libbpf'...
error: RPC failed; curl 56 GnuTLS recv error (-54): Error in the pull function.
error: 6602 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
fatal: clone of 'https://github.com/libbpf/libbpf.git' into submodule path '/home/user/bcc/libbpf-tools/bpftool/libbpf' failed
Failed to clone 'libbpf'. Retry scheduled
Cloning into '/home/user/bcc/libbpf-tools/bpftool/libbpf'...
fatal: unable to access 'https://github.com/libbpf/libbpf.git/': Failed to connect to github.com port 443 after 135117 ms: Connection timed out
fatal: clone of 'https://github.com/libbpf/libbpf.git' into submodule path '/home/user/bcc/libbpf-tools/bpftool/libbpf' failed
Failed to clone 'libbpf' a second time, aborting
Submodule path 'src/cc/libbpf': checked out '02bdeb7a2c2e7cb2c9cecb125527a9c5a6bbf139'
Submodule path 'libbpf-tools/bpftool': checked out '6eb3e20583da834da18ea3011dcefd08b3493f8d'
Cloning into '/home/user/bcc/libbpf-tools/bpftool/libbpf'...
Submodule path 'libbpf-tools/bpftool/libbpf': checked out '7984737fbf3b2a14a86321387bb62abb16cfc4ed'
Submodule path 'src/cc/libbpf': checked out '02bdeb7a2c2e7cb2c9cecb125527a9c5a6bbf139'
fatal: Failed to recurse into submodule path 'libbpf-tools/bpftool'
CMake Warning at CMakeLists.txt:66 (message):
  Failed to update submodule libbpf


-- Latest recognized Git tag is v0.35.0
-- Git HEAD is 9691c56891fb833351d3cfe69bda4a57076c3b62
-- Revision is 0.35.0+9691c568 (major 0, minor 35, patch 0)
-- Kernel release: 6.6.63-linux
-- Kernel headers: /usr/src/linux-headers-6.6.63-linux
-- Found LLVM: /usr/lib/llvm-11/include 11.1.0 (Use LLVM_ROOT envronment variable for another version of LLVM)
-- Could NOT find LibDebuginfod (missing: LIBDEBUGINFOD_LIBRARIES LIBDEBUGINFOD_INCLUDE_DIRS) 
-- Using static-libstdc++
-- Could NOT find LuaJIT (missing: LUAJIT_LIBRARIES LUAJIT_INCLUDE_DIR) 
CMake Warning at tests/python/CMakeLists.txt:6 (message):
  Recommended test program 'arping' not found


CMake Warning at tests/python/CMakeLists.txt:10 (message):
  Recommended test program 'netperf' not found


CMake Warning at tests/python/CMakeLists.txt:16 (message):
  Recommended test program 'iperf' or 'iperf3' not found


-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/bcc/build

已经不报错了

user@Ubuntu:~/bcc/build$ cmake ..
-- Latest recognized Git tag is v0.35.0
-- Git HEAD is 9691c56891fb833351d3cfe69bda4a57076c3b62
-- Revision is 0.35.0+9691c568 (major 0, minor 35, patch 0)
-- Kernel release: 6.6.63-linux
-- Kernel headers: /usr/src/linux-headers-6.6.63-linux
-- Found LLVM: /usr/lib/llvm-11/include 11.1.0 (Use LLVM_ROOT envronment variable for another version of LLVM)
-- Could NOT find LibDebuginfod (missing: LIBDEBUGINFOD_LIBRARIES LIBDEBUGINFOD_INCLUDE_DIRS) 
-- Using static-libstdc++
-- Could NOT find LuaJIT (missing: LUAJIT_LIBRARIES LUAJIT_INCLUDE_DIR) 
CMake Warning at tests/python/CMakeLists.txt:6 (message):
  Recommended test program 'arping' not found


CMake Warning at tests/python/CMakeLists.txt:10 (message):
  Recommended test program 'netperf' not found


CMake Warning at tests/python/CMakeLists.txt:16 (message):
  Recommended test program 'iperf' or 'iperf3' not found


-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/bcc/build
user@Ubuntu:~/bcc/build$ 
user@Ubuntu:~/bcc/build$ ls /usr/src/linux-headers-6.6.63-linux
arch  include  Makefile  Module.symvers  scripts

重新开始编译

user@Ubuntu:~/bcc/build$ make
Consolidate compiler generated dependencies of target clang_frontend-objects
[  1%] Building CXX object src/cc/frontends/clang/CMakeFiles/clang_frontend-objects.dir/b_frontend_action.cc.o
In file included from /usr/lib/llvm-11/include/clang/AST/RecursiveASTVisitor.h:23,
                 from /home/user/bcc/src/cc/frontends/clang/b_frontend_action.h:23,
                 from /home/user/bcc/src/cc/frontends/clang/b_frontend_action.cc:31:
... ...
[ 95%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_libbcc.cc.o
[ 95%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_c_api.cc.o
[ 95%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_array_table.cc.o
[ 96%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_bpf_table.cc.o
[ 96%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_cg_storage.cc.o
[ 96%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_hash_table.cc.o
[ 97%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_map_in_map.cc.o
[ 97%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_perf_event.cc.o
[ 97%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_pinned_table.cc.o
[ 97%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_prog_table.cc.o
[ 98%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_queuestack_table.cc.o
[ 98%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_shared_table.cc.o
[ 98%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_sk_storage.cc.o
[ 99%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_sock_table.cc.o
[ 99%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_usdt_args.cc.o
[ 99%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_usdt_probes.cc.o
[100%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/utils.cc.o
[100%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_parse_tracepoint.cc.o
[100%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_zip.cc.o
[100%] Linking CXX executable test_libbcc
[100%] Built target test_libbcc
user@Ubuntu:~/bcc/build$ 

最后安装

user@Ubuntu:~/bcc/build$ sudo make install
Consolidate compiler generated dependencies of target clang_frontend-objects
[  1%] Built target clang_frontend-objects
[  1%] Built target clang_frontend
... ...
-- Installing: /usr/share/bcc/tools/old/tcpaccept
-- Installing: /usr/share/bcc/tools/old/tcpconnect
-- Installing: /usr/share/bcc/tools/old/tcptop
-- Installing: /usr/share/bcc/tools/old/wakeuptime

参考

ubuntu 缺少 libtinfo.so.5 问题
https://blog.youkuaiyun.com/lsqtzj/article/details/108553576

执行/usr/share/bcc/tools/filetop -C报错Exception: Failed to compile BPF module 
https://blog.youkuaiyun.com/liuqiuxiu/article/details/108421958

Could not connect to archive.ubuntukylin.com:10006 (120.240.95.35), connection timed out
https://blog.youkuaiyun.com/shanpenghui/article/details/108552367

ImportError: No module named 通用解决方法
https://blog.youkuaiyun.com/jdbc/article/details/80351833

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值