blob: d90002580d716c86c0864d7e288fc65dc3ea9450 [file] [log] [blame]
Brendan Gregg38cef482016-01-15 17:26:30 -08001Demonstrations of stacksnoop, the Linux eBPF/bcc version.
2
3
4This program traces the given kernel function and prints the kernel stack trace
5for every call. This tool is useful for studying low frequency kernel functions,
6to see how they were invoked. For exmaple, tracing the ext4_sync_fs() call:
7
8# ./stacksnoop ext4_sync_fs
9TIME(s) STACK
1042005194.132250004
1142005194.132253997 ip: ffffffff81280461 ext4_sync_fs
1242005194.132256001 r0: ffffffff811ed7f9 iterate_supers
1342005194.132257000 r1: ffffffff8121ba25 sys_sync
1442005194.132257000 r2: ffffffff81775cb6 entry_SYSCALL_64_fastpath
1542005194.132275000
1642005194.132275999 ip: ffffffff81280461 ext4_sync_fs
1742005194.132275999 r0: ffffffff811ed7f9 iterate_supers
1842005194.132276997 r1: ffffffff8121ba35 sys_sync
1942005194.132276997 r2: ffffffff81775cb6 entry_SYSCALL_64_fastpath
20
21This shows that ext4_sync_fs() was called by iterate_supers(), which was called
22by sys_sync(), and so on. (It tells me that this was a syscall invoked sync,
23so an application has requested it.)
24
25The "ip" refers to the instruction pointer, and the "r#" refers to the return
26address for each stack frame.
27
28For high frequency functions, see stackcount, which summarizes in-kernel for
29efficiency. If you don't know if your function is low or high frequency, try
30funccount.
31
32
33The -v option includes more fields, including the on-CPU process (COMM and PID):
34
35# ./stacksnoop -v ext4_sync_fs
36TIME(s) COMM PID CPU STACK
3742005557.056332998 sync 22352 1
3842005557.056336999 sync 22352 1 ip: ffffffff81280461 ext4_sync_fs
3942005557.056339003 sync 22352 1 r0: ffffffff811ed7f9 iterate_supers
4042005557.056340002 sync 22352 1 r1: ffffffff8121ba25 sys_sync
4142005557.056340002 sync 22352 1 r2: ffffffff81775cb6 entry_SYSCALL_64_fastpath
4242005557.056358002 sync 22352 1
4342005557.056358002 sync 22352 1 ip: ffffffff81280461 ext4_sync_fs
4442005557.056359001 sync 22352 1 r0: ffffffff811ed7f9 iterate_supers
4542005557.056359999 sync 22352 1 r1: ffffffff8121ba35 sys_sync
4642005557.056359999 sync 22352 1 r2: ffffffff81775cb6 entry_SYSCALL_64_fastpath
47
48This identifies the application issuing the sync syscall: the sync(1) command
49(COMM column).
50
51
52Here's another example, showing the path to second_overflow() and on-CPU
53process:
54
55# ./stacksnoop -v second_overflow
56TIME(s) COMM PID CPU STACK
5742005696.529449999 <idle> 0 0
5842005696.529457003 <idle> 0 0 ip: ffffffff810e5701 second_overflow
5942005696.529459000 <idle> 0 0 r0: ffffffff810ecb1b tick_do_update_jiffies64
6042005696.529459998 <idle> 0 0 r1: ffffffff810ed6e0 tick_irq_enter
6142005696.529459998 <idle> 0 0 r2: ffffffff8107a195 irq_enter
6242005696.529460996 <idle> 0 0 r3: ffffffff8146bb6f xen_evtchn_do_upcall
6342005696.529460996 <idle> 0 0 r4: ffffffff81777a2e xen_do_hypervisor_callback
6442005697.616295002 <idle> 0 0
6542005697.616301000 <idle> 0 0 ip: ffffffff810e5701 second_overflow
6642005697.616302997 <idle> 0 0 r0: ffffffff810ecb1b tick_do_update_jiffies64
6742005697.616304003 <idle> 0 0 r1: ffffffff810ed6e0 tick_irq_enter
6842005697.616304003 <idle> 0 0 r2: ffffffff8107a195 irq_enter
6942005697.616305001 <idle> 0 0 r3: ffffffff8146bb6f xen_evtchn_do_upcall
7042005697.616305001 <idle> 0 0 r4: ffffffff81777a2e xen_do_hypervisor_callback
7142005698.556240998 <idle> 0 1
7242005698.556247003 <idle> 0 1 ip: ffffffff810e5701 second_overflow
7342005698.556249000 <idle> 0 1 r0: ffffffff810ecb1b tick_do_update_jiffies64
7442005698.556249000 <idle> 0 1 r1: ffffffff810ed6e0 tick_irq_enter
7542005698.556249999 <idle> 0 1 r2: ffffffff8107a195 irq_enter
7642005698.556249999 <idle> 0 1 r3: ffffffff8146bb6f xen_evtchn_do_upcall
7742005698.556250997 <idle> 0 1 r4: ffffffff81777a2e xen_do_hypervisor_callback
78[...]
79
80This fires every second (see TIME(s)), and is from tick_do_update_jiffies64().
81
82
83USAGE message:
84
85# ./stacksnoop -h
86usage: stacksnoop [-h] [-p PID] [-s] [-v] function
87
88Trace and print kernel stack traces for a kernel function
89
90positional arguments:
91 function kernel function name
92
93optional arguments:
94 -h, --help show this help message and exit
95 -p PID, --pid PID trace this PID only
96 -s, --offset show address offsets
97 -v, --verbose print more fields
98
99examples:
100 ./stacksnoop ext4_sync_fs # print kernel stack traces for ext4_sync_fs
101 ./stacksnoop -s ext4_sync_fs # ... also show symbol offsets
102 ./stacksnoop -v ext4_sync_fs # ... show extra columns
103 ./stacksnoop -p 185 ext4_sync_fs # ... only when PID 185 is on-CPU