在Linux中通过perf为未列出的功能添加动态跟踪点 [英] Adding dynamic tracepoint through perf in Linux for function that is not listed
问题描述
我正在尝试使用 perf
从mm/memory.c跟踪函数zap_pte_range
.但是功能未在perf probe -F
中列出.有没有办法动态跟踪此功能? IE.显式添加跟踪点并重新编译内核?
I am trying to trace function zap_pte_range
from mm/memory.c using perf
. But function is not listed in the perf probe -F
. So is there a way to dynamically trace this function? I.e. with explicitly adding the tracepoint and recompiling the kernel?
perf probe -a zap_pte_range
给予:
找不到构建ID为33b15ec444475ee7806331034772f61666fa6719的[kernel.kallsyms],继续,没有符号
[kernel.kallsyms] with build id 33b15ec444475ee7806331034772f61666fa6719 not found, continuing without symbols
无法在内核中找到符号zap_pte_range
Failed to find symbol zap_pte_range in kernel
错误:无法添加事件.
推荐答案
没有这样的跟踪点.因此,显然您无法轻松地跟踪它.似乎该函数已由编译器内联(请注意,出于某些优化原因,也可以省略该函数).这就是为什么 /proc/kallsyms
中没有其符号的原因.
There is no such trace point. So apparently you cannot trace it the easy way. It seems that this function was inlined by compiler (keep in mind that function also could be omitted for some optimization reasons). That's why there is no its symbol in /proc/kallsyms
.
您可以选择最适合您的功能进行跟踪.例如.在具有4.9内核的Debian中,我可以跟踪 unmap_page_range()
,它最终会调用"您需要的功能.也许在逻辑上可以满足您的目标.
You can choose the most suitable function for you to trace. E.g. in my Debian with 4.9 kernel I can trace unmap_page_range()
, which eventually "calls" the function you need. Perhaps it logically will meet your goal.
另一种方法是一点点黑客攻击.您可以执行类似objdump -dS memory.o | vim -
的操作(您应该具有二进制文件),并研究所需的代码在哪里.考虑到链zap_pud_range()
-> zap_pmd_range()
-> zap_pte_range()
可能是内联的,您将必须研究上述的unmap_page_range()
.也许您最终将获得 kprobes .
Another way is a little bit hacking. You can do something like objdump -dS memory.o | vim -
(you should have binaries) and investigate where is the code you needed. Given that the chain zap_pud_range()
->zap_pmd_range()
->zap_pte_range()
is probably inlined, you will have to investigate aforementioned unmap_page_range()
. Perhaps you'll finally gain some code address for kprobes.
如果要显式跟踪zap_pte_range()
,例如通过 jprobes (关于args)或 kretprobes (关于返回值),您可以尝试指定
If you want to explicitly trace zap_pte_range()
e.g. through jprobes (about args) or kretprobes (about return value), you can try to specify noinline
-attribute for needed function(s), recompile Linux kernel and trace it as you want.
猜猜我没有其他有用的方法了.
Guess I have no more useful ways for you.
更多信息: 相关帖子, Ftrace:跟踪内核功能!, man nm
More info: Related post, Jprobes example, Ftrace: trace your kernel functions!, Post about ftrace and systemtap, man nm
这篇关于在Linux中通过perf为未列出的功能添加动态跟踪点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!