Red Hat Training
A Red Hat training course is available for RHEL 8
24.2. 在带有 perf 的函数内创建 uprobes
然后,这些追踪点可以与其他 perf
工具(如 perf stat
和 perf 记录
)一起使用,以更好地理解进程或应用程序行为。
先决条件
-
已安装
perf
用户空间工具,如安装 perf 所述。 您已获得可执行文件的调试符号:
# objdump -t ./your_executable | head
注意要做到这一点,必须安装可执行文件的
debuginfo
软件包;或者,如果可执行文件是本地开发的应用程序,则必须使用调试信息(GCC 中的-g
选项)编译应用程序。
流程
查看可放置 uprobe 的功能行:
$ perf probe -x ./your_executable -L main
这个命令的输出结果类似如下:
<main@/home/user/my_executable:0> 0 int main(int argc, const char **argv) 1 { int err; const char *cmd; char sbuf[STRERR_BUFSIZE]; /* libsubcmd init */ 7 exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT); 8 pager_init(PERF_PAGER_ENVIRONMENT);
为所需的功能行创建 uprobe:
# perf probe -x ./my_executable main:8 Added new event: probe_my_executable:main_L8 (on main:8 in /home/user/my_executable) You can now use it in all perf tools, such as: perf record -e probe_my_executable:main_L8 -aR sleep 1