15.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