Ftrace跟踪内核

获取内核模块进程号
printk(“info (pid=%d comm=%d)\n”, current->pid,current->comm);

开启ftrace跟踪特定函数 这里是 __alloc_pages_nodemask

#!/bin/sh

dir=/sys/kernel/debug/tracing

sysctl kernel.ftrace_enabled=1
echo nop > ${dir}/current_tracer
echo function_graph > ${dir}/current_tracer
echo __alloc_pages_nodemask > ${dir}/set_graph_function
echo 10 >  ${dir}/max_graph_depth
echo 1 > ${dir}/tracing_on
sleep 1
#echo 
read -p '按任意键exit' name
echo "finished"
echo 0 > ${dir}/tracing_on
cat ${dir}/trace > showtrace.txt
#echo nop > current_tracer;//清空tracer
#echo function_graph > current_tracer;//使用图形显示调用关系
#echo ip_rcv > set_graph_function;//设置过滤函数,可以设置多个
#echo 1 > tracing_enabled开始追踪

根据进程号过滤跟踪日志

------------------------------------------
   0)  insmod-14593  =>  dmesg-14595  
 ------------------------------------------

   0)               |  __alloc_pages_nodemask() {
   0)               |    _cond_resched() {
   0)   0.227 us    |      rcu_all_qs();
   0)   0.634 us    |    }
   0)               |    get_page_from_freelist() {
   0)   0.157 us    |      __inc_numa_state();
   0)   0.154 us    |      __inc_numa_state();
   0)   1.800 us    |    }
   0)   3.898 us    |  }
   0)               |  __alloc_pages_nodemask() {
   0)               |    _cond_resched() {
   0)   0.153 us    |      rcu_all_qs();
   0)   0.509 us    |    }
   0)               |    get_page_from_freelist() {
   0)   0.156 us    |      __inc_numa_state();
   0)   0.154 us    |      __inc_numa_state();
   0)   1.048 us    |    }
   0)   2.092 us    |  }

小遗憾是不可能跟踪所有函数,但是很多函数可以跟踪到,有个函数列表,可以查看是否能跟踪命令如下:
cat available_filter_functions

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值