2018-07-17 ftrace

https://elixir.bootlin.com/linux/latest/source/Documentation/trace/ftrace.rst
【转】linux ftrace原理
From: http://www.360doc.com/content/16/0126/13/10366845_530659813.shtml

Tested on Linux kernel 4.8.17


ftrace 系列文章的一个索引

最后,这里是我找到的一些 ftrace 方面的文章。它们大部分在 LWN (Linux 新闻周刊)上,它是 Linux 的一个极好的资源(你可以购买一个 订阅!)

作者:
链接:https://www.imooc.com/article/29575?block_id=tuijian_wz
来源:慕课网


指定函数深度

From: http://terenceli.github.io/技术/2017/12/05/tracing1

echo 2 > max_graph_depth

function graph tracer

【转】ftrace 简介

image.png

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
image.png
  • 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 的输出

【转】ftrace 的使用

From: https://www.cnblogs.com/jefree/p/4438975.html
2、 一旦将函数追踪器启动,ftrace会记录所有函数的运行情况,但是我们只想查看schedule函数的调用情况,因此先设置函数过滤器,仅记录schedule:

   root@thinker:/sys/kernel/debug/tracing#echo schedule > set_ftrace_filter

Schedule switch tracer 记录系统中的进程切换信息。在其输出文件 trace 中 , 输出行的格式有两种:

第一种表示进程切换信息:

Context switches:
Previous task Next Task
<pid>:<prio>:<state> ==> <pid>:<prio>:<state>
第二种表示进程 wakeup 的信息:

Wake ups: 
   Current task               Task waking up 

<pid>:<prio>:<state> + <pid>:<prio>:<state>
这里举一个实例:

# 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

第一行表示进程 fon 进程 wakeup 了 bash 进程。其中 fon 进程的 pid 为 6263,优先级为 120,进程状态为 Ready 。她将进程 ID 为 2717 的 bash 进程唤醒。

第二行表示进程切换发生,从 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.


image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 【陈雄聊太极拳 2】苦练出功夫的诀窍 2018-04-07陈雄和美太极 《和美太极》中国专业太极微刊 陈雄老师聊太...
    阿德乐阅读 6,223评论 1 6
  • 你不必欢喜,世间比想像的好,人情比想象的真,让一份温暖永存心底,让一点感动稍稍压抑。那一点点的泪花,也不要开放,悄...
    雨木西阅读 230评论 2 2
  • 生活逼迫我们不得不习惯!
    安安安嶺阅读 258评论 0 0
  • 最近工作的竞争性增强了。由于考核机制是随着整体的业绩来变动的,简单点说,大家如果都进步了,自己没有进步,就是垫底的...
    张闻凯初诺阅读 141评论 0 0