简体   繁体   English

在Linux中通过perf为未列出的功能添加动态跟踪点

[英]Adding dynamic tracepoint through perf in Linux for function that is not listed

I am trying to trace function zap_pte_range from mm/memory.c using perf . 我正在尝试使用perf从mm / memory.c跟踪函数zap_pte_range But function is not listed in the perf probe -F . 但是性能未在perf probe -F列出。 So is there a way to dynamically trace this function? 有没有办法动态跟踪此功能? Ie with explicitly adding the tracepoint and recompiling the kernel? 即显式添加跟踪点并重新编译内核?

perf probe -a zap_pte_range

gives: 给出:

[kernel.kallsyms] with build id 33b15ec444475ee7806331034772f61666fa6719 not found, continuing without symbols 找不到[Build.ID:33b15ec444475ee7806331034772f61666fa6719]的[kernel.kallsyms],继续,没有符号

Failed to find symbol zap_pte_range in kernel 无法在内核中找到符号zap_pte_range

Error: Failed to add events. 错误:添加事件失败。

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 . 这就是为什么/proc/kallsyms没有其符号的原因。

You can choose the most suitable function for you to trace. 您可以选择最合适的功能进行跟踪。 Eg in my Debian with 4.9 kernel I can trace unmap_page_range() , which eventually "calls" the function you need. 例如,在带有4.9内核的Debian中,我可以跟踪unmap_page_range() ,最终它会“调用”您需要的功能。 Perhaps it logically will meet your goal. 也许在逻辑上可以满足您的目标。

Another way is a little bit hacking. 另一种方法是一点点黑客。 You can do something like objdump -dS memory.o | vim - 您可以执行objdump -dS memory.o | vim - objdump -dS memory.o | vim - (you should have binaries) and investigate where is the code you needed. objdump -dS memory.o | vim - (您应该有二进制文件)并调查所需的代码在哪里。 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() . 鉴于链zap_pud_range() -> zap_pmd_range() -> zap_pte_range()可能是内联的,您将不得不研究上述的unmap_page_range() Perhaps you'll finally gain some code address for kprobes . 也许您最终会为kprobes获得一些代码地址。

If you want to explicitly trace zap_pte_range() eg 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. 如果要通过jprobes (关于args)或kretprobes (关于返回值)显式跟踪zap_pte_range() ,则可以尝试为所需函数指定noinline -attribute,重新编译Linux内核并根据需要进行跟踪。

Guess I have no more useful ways for you. 猜猜我没有适合您的有用方法。

More info: Related post , Jprobes example , Ftrace: trace your kernel functions! 更多信息: 相关文章Jprobes示例Ftrace:跟踪您的内核功能! , Post about ftrace and systemtap , man nm 关于ftrace和systemtap的帖子man nm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM