https://elixir.bootlin.com/linux/latest/source/Documentation/trace/ftrace.rst
【轉(zhuǎn)】linux ftrace原理
From: http://www.360doc.com/content/16/0126/13/10366845_530659813.shtml
Tested on Linux kernel 4.8.17
ftrace 系列文章的一個(gè)索引
最后,這里是我找到的一些 ftrace 方面的文章轮锥。它們大部分在 LWN (Linux 新聞周刊)上矫钓,它是 Linux 的一個(gè)極好的資源(你可以購(gòu)買(mǎi)一個(gè) 訂閱!)
使用 Ftrace 調(diào)試內(nèi)核 - part 1 (Dec 2009, Steven Rostedt)
使用 Ftrace 調(diào)試內(nèi)核 - part 2 (Dec 2009, Steven Rostedt)
Linux 函數(shù)跟蹤器的秘密 (Jan 2010, Steven Rostedt)
trace-cmd:Ftrace 的一個(gè)前端 (Oct 2010, Steven Rostedt)
使用 KernelShark 去分析實(shí)時(shí)調(diào)試器 (2011, Steven Rostedt)
Ftrace: 神秘的開(kāi)關(guān) (2014, Brendan Gregg)
內(nèi)核文檔:(它十分有用) Documentation/ftrace.txt
你能跟蹤的事件的文檔 Documentation/events.txt
linux 內(nèi)核開(kāi)發(fā)上的一些 ftrace 設(shè)計(jì)文檔 (不是有用舍杜,而是有趣新娜!) Documentation/ftrace-design.txt
作者:
鏈接:https://www.imooc.com/article/29575?block_id=tuijian_wz
來(lái)源:慕課網(wǎng)
指定函數(shù)深度
From: http://terenceli.github.io/技術(shù)/2017/12/05/tracing1
echo 2 > max_graph_depth
function graph tracer
Flags::
'$' - greater than 1 second
'@' - greater than 100 milisecond
'*' - greater than 10 milisecond
'#' - greater than 1000 microsecond
'!' - greater than 100 microsecond
'+' - greater than 10 microsecond
' ' - less than or equal to 10 microsecond.
xy@ubuntu:/boot$ ag 'CONFIG_DYNAMIC_FTRACE' -i /boot/config-4.8.17
8411:CONFIG_DYNAMIC_FTRACE=y
8412:CONFIG_DYNAMIC_FTRACE_WITH_REGS=y
- script
# 2. function graph tracer (valified)
# use root with sudo -s
echo function_graph > /sys/kernel/debug/tracing/current_tracer
cat -n /sys/kernel/debug/tracing/current_tracer
echo
echo do_mount copy_mnt_ns > /sys/kernel/debug/tracing/set_graph_function
cat -n /sys/kernel/debug/tracing/set_graph_function
# run test process and then
cat -n /sys/kernel/debug/tracing/trace
Schedule switch tracer 的輸出
From: https://www.cnblogs.com/jefree/p/4438975.html
2、 一旦將函數(shù)追蹤器啟動(dòng)既绩,ftrace會(huì)記錄所有函數(shù)的運(yùn)行情況概龄,但是我們只想查看schedule函數(shù)的調(diào)用情況,因此先設(shè)置函數(shù)過(guò)濾器熬词,僅記錄schedule:
root@thinker:/sys/kernel/debug/tracing#echo schedule > set_ftrace_filter
Schedule switch tracer 記錄系統(tǒng)中的進(jìn)程切換信息旁钧。在其輸出文件 trace 中 , 輸出行的格式有兩種:
第一種表示進(jìn)程切換信息:
Context switches:
Previous task Next Task
<pid>:<prio>:<state> ==> <pid>:<prio>:<state>
第二種表示進(jìn)程 wakeup 的信息:
Wake ups:
Current task Task waking up
<pid>:<prio>:<state> + <pid>:<prio>:<state>
這里舉一個(gè)實(shí)例:
# tracer: sched_switch
#
# TASK_PID CPU# TIMESTAMP FUNCTION
# | | | |
fon-6263 [000] 4154504638.932214: 6263:120:R + 2717:120:S
fon-6263 [000] 4154504638.932214: 6263:120:? ==> 2717:120:R
bash-2717 [000] 4154504638.932214: 2717:120:S + 2714:120:S
第一行表示進(jìn)程 fon 進(jìn)程 wakeup 了 bash 進(jìn)程。其中 fon 進(jìn)程的 pid 為 6263互拾,優(yōu)先級(jí)為 120歪今,進(jìn)程狀態(tài)為 Ready 。她將進(jìn)程 ID 為 2717 的 bash 進(jìn)程喚醒颜矿。
第二行表示進(jìn)程切換發(fā)生寄猩,從 fon 切換到 bash 。
Stack trace
Since the kernel has a fixed sized stack, it is important not to
waste it in functions. A kernel developer must be conscience of
what they allocate on the stack. If they add too much, the system
can be in danger of a stack overflow, and corruption will occur,
usually leading to a system panic.
There are some tools that check this, usually with interrupts
periodically checking usage. But if you can perform a check
at every function call that will become very useful. As ftrace provides
a function tracer, it makes it convenient to check the stack size
at every function call. This is enabled via the stack tracer.
CONFIG_STACK_TRACER enables the ftrace stack tracing functionality.