本文将介绍如何利用perf-tools的funcgraph traces a graph of kernel function calls, showing children and times。既有助于学习内核源码,也有助于debug。

Prerequisites

https://github.com/brendangregg/perf-tools#prerequisites

安装

https://github.com/brendangregg/perf-tools#install

文档

官方文档:funcgraph_example.txt

文档值得好好研究!

使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ ./funcgraph 
USAGE: funcgraph [-aCDhHPtT] [-m maxdepth] [-p PID] [-L TID] [-d secs] funcstring
-a # all info (same as -HPt)
-C # measure on-CPU time only
-d seconds # trace duration, and use buffers
-D # do not show function duration
-h # this usage message
-H # include column headers
-m maxdepth # max stack depth to show
-p PID # trace when this pid is on-CPU
-L TID # trace when this thread is on-CPU
-P # show process names & PIDs
-t # show timestamps
-T # comment function tails
eg,
funcgraph do_nanosleep # trace do_nanosleep() and children
funcgraph -m 3 do_sys_open # trace do_sys_open() to 3 levels only
funcgraph -a do_sys_open # include timestamps and process name
funcgraph -p 198 do_sys_open # trace vfs_read() for PID 198 only
funcgraph -d 1 do_sys_open >out # trace 1 sec, then write to file

See the man page and example file for more info.

参考资料:

  1. eBPF+Ftrace 合璧剑指:no space left on device?