Learning Linux kernel function calls using Ftrace

Source: Internet
Author: User

Reprint: http://blog.csdn.net/ronliu/article/details/6446251

The use of function pointer hooks in Linux makes it difficult to read code. For example, if you want to know the invocation path of a function, you can only look at the code with a tool such as source insight. Is there a way to get the overall impression of a call relationship quickly? Ftrace is a debugging tool provided by the kernel that can track what is happening in the kernel. such as function call, process switch, interrupt switch and so on. This tool is used to track function calls.

# cat/boot/config-2.6.36 | grep ftraceconfig_have_ftrace_nmi_enter=yconfig_have_dynamic_ftrace=yconfig_have_ftrace_mcount_record=yconfig_ Ftrace_nmi_enter=yconfig_ftrace=y                           #FTRACE打开后, the-PG option is turned on when the kernel is compiled. config_ftrace_syscalls=yconfig_dynamic_ftrace=yconfig_ftrace_mcount_record=y# CONFIG_FTRACE_STARTUP_TEST is not Set

Mkdir/debug
Mount-t Debugfs nodev/debug #挂载debugfs. Ftrace using Debugfs as a configuration tool
CD tracing #检查是否存在tracing文件夹. If it does not exist, the current kernel does not support ftrace and needs to be recompiled. Reference documents
There are many files in the tracing folder for configuring the Ftrace tool.

echo NOP > Current_tracer #清楚当前tracer. When you do this, the PID is emptied.
echo function > Current_tracer #跟踪函数调用
echo 1 > Tracing_enabled #打开ftrace开始跟踪
echo 0 > tracing_enabled #关闭ftrace停止跟踪
Cat Trace | Less # Read the trace file. Tools such as Vim can be used.



echo 1 > Set_ftrace_pid function call #跟踪单个进程 (kernel thread). Valid values are greater than 0. This option is cleared if echo > set_ftrace_pid.

echo function_graph > Current_tracer #以图形化的方式跟踪函数调用. As shown in. It works very well.



By default, all kernel function calls are captured. You can filter by using the following command, capturing only the function calls that are of interest.
echo sys_socket > Set_graph_function #可以写多个函数. You can also use a wildcard character *, such as sys_*.
Cat Available_filter_functions | grep sys_ #查询ftrace支持的包含sys_字符的函数. Note that a function declared in the kernel using Export_symbol can use Ftrace tracing.

Reference Documentation:
1. Ftrace User manual: Kernel-srctree/documentation/trace/ftrace.txt
2. Ftrace Design Document: Kernel-srctree/documentation/trace/ftrace-design.txt
3. http://www.ibm.com/developerworks/cn/linux/l-cn-ftrace/index.html

Learning Linux kernel function calls using Ftrace

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.