$ perf
WARNING: perf not found for kernel 6.2.0-35
You may need to install the following packages for this specific kernel:
linux-tools-6.2.0-35-generic
linux-cloud-tools-6.2.0-35-generic
You may also want to install one of the following packages to keep up to date:
linux-tools-generic
linux-cloud-tools-generic
echo"deb http://ddebs.ubuntu.com $(lsb_release -cs) main restricted universe multiverse
deb http://ddebs.ubuntu.com $(lsb_release -cs)-updates main restricted universe multiverse
deb http://ddebs.ubuntu.com $(lsb_release -cs)-proposed main restricted universe multiverse"|\
sudo tee -a /etc/apt/sources.list.d/ddebs.list
$ sudo perf record -e sched:sched_switch -a -g sleep 1
在执行这个命令的时候可能遇到下面的错误:
1
2
3
4
5
event syntax error: 'sched:sched_switch'
\___ unsupported tracepoint
libtraceevent is necessary for tracepoint support
Run 'perf list' for a list of valid events
错误信息说明不支持 sched:sched_switch 这个 tracepoint。我们运行 perf list 查看可用的 tracepoint:
1
2
3
4
5
6
7
8
9
$ sudo perf list 'sched:*'List of pre-defined events (to be used in -e or -M):
...
sched:sched_stat_wait [Tracepoint event] sched:sched_stick_numa [Tracepoint event] sched:sched_swap_numa [Tracepoint event] sched:sched_switch [Tracepoint event] sched:sched_wait_task [Tracepoint event]...
输出中明明包含了 sched:sched_switch,为什么 perf 不支持呢?
使用 perf version --build-options 查看 perf 的 build 选项:
$ perf version --build-options
perf version 6.2.16
dwarf: [ on ]# HAVE_DWARF_SUPPORT dwarf_getlocations: [ on ]# HAVE_DWARF_GETLOCATIONS_SUPPORT glibc: [ on ]# HAVE_GLIBC_SUPPORT syscall_table: [ on ]# HAVE_SYSCALL_TABLE_SUPPORT libbfd: [ OFF ]# HAVE_LIBBFD_SUPPORT debuginfod: [ OFF ]# HAVE_DEBUGINFOD_SUPPORT libelf: [ on ]# HAVE_LIBELF_SUPPORT libnuma: [ on ]# HAVE_LIBNUMA_SUPPORTnuma_num_possible_cpus: [ on ]# HAVE_LIBNUMA_SUPPORT libperl: [ OFF ]# HAVE_LIBPERL_SUPPORT libpython: [ OFF ]# HAVE_LIBPYTHON_SUPPORT libslang: [ on ]# HAVE_SLANG_SUPPORT libcrypto: [ on ]# HAVE_LIBCRYPTO_SUPPORT libunwind: [ on ]# HAVE_LIBUNWIND_SUPPORT libdw-dwarf-unwind: [ on ]# HAVE_DWARF_SUPPORT zlib: [ on ]# HAVE_ZLIB_SUPPORT lzma: [ on ]# HAVE_LZMA_SUPPORT get_cpuid: [ on ]# HAVE_AUXTRACE_SUPPORT bpf: [ on ]# HAVE_LIBBPF_SUPPORT aio: [ on ]# HAVE_AIO_SUPPORT zstd: [ OFF ]# HAVE_ZSTD_SUPPORT libpfm4: [ OFF ]# HAVE_LIBPFM libtraceevent: [ OFF ]# HAVE_LIBTRACEEVENT