Skip to content

perf 工具 ​

perf 工具的组件名称为 perf, 相关内核选项为

ini
# General setup
# -> Kernel Performance Events And Counters
# -> Kernel performance events and counters
CONFIG_PERF_EVENTS=y

# Kernel hacking
# -> Tracers
# -> Enable kprobes-based dynamic events
CONFIG_KPROBE_EVENTS=y

# Kernel hacking
# -> Tracers
# -> Enable uprobes-based dynamic events
CONFIG_UPROBE_EVENTS=y

检查工具为

bash
#!/bin/bash

source ./kernel_config_utils.sh
source ./net_utils.sh

perf_check() {
    is_error=false
    if ! kernel_config_check CONFIG_PERF_EVENTS; then
        is_error=true
    fi
    if ! kernel_config_check CONFIG_KPROBE_EVENTS; then
        is_error=true
    fi
    if ! kernel_config_check CONFIG_UPROBE_EVENTS; then
        is_error=true
    fi
    if [ "$is_error" == "true" ]; then
        return 1
    fi

    return 0
}

如果 /proc/kcore 文件不存在, perf 相关命令可能无法查看内核符号汇编显示以下内容:

Note that annotation using /proc/kcore requires CAP_SYS_RAWIO capability