Brendan Gregg | 38cef48 | 2016-01-15 17:26:30 -0800 | [diff] [blame] | 1 | Demonstrations of stacksnoop, the Linux eBPF/bcc version. |
| 2 | |
| 3 | |
| 4 | This program traces the given kernel function and prints the kernel stack trace |
| 5 | for every call. This tool is useful for studying low frequency kernel functions, |
Vicent Marti | 592414e | 2016-03-27 18:22:03 +0200 | [diff] [blame] | 6 | to see how they were invoked. For example, tracing the submit_bio() call: |
Brendan Gregg | 38cef48 | 2016-01-15 17:26:30 -0800 | [diff] [blame] | 7 | |
Vicent Marti | 592414e | 2016-03-27 18:22:03 +0200 | [diff] [blame] | 8 | # ./stacksnoop submit_bio |
| 9 | TIME(s) SYSCALL |
| 10 | 3592.838736000 submit_bio |
Sasha Goldshtein | 2bf3ff3 | 2017-02-08 23:25:00 -0500 | [diff] [blame] | 11 | submit_bio |
| 12 | submit_bh |
| 13 | jbd2_journal_commit_transaction |
| 14 | kjournald2 |
| 15 | kthread |
| 16 | ret_from_fork |
Brendan Gregg | 38cef48 | 2016-01-15 17:26:30 -0800 | [diff] [blame] | 17 | |
Vicent Marti | 592414e | 2016-03-27 18:22:03 +0200 | [diff] [blame] | 18 | This shows that submit_bio() was called by submit_bh(), which was called |
| 19 | by jbd2_journal_commit_transaction(), and so on. |
Brendan Gregg | 38cef48 | 2016-01-15 17:26:30 -0800 | [diff] [blame] | 20 | |
| 21 | For high frequency functions, see stackcount, which summarizes in-kernel for |
| 22 | efficiency. If you don't know if your function is low or high frequency, try |
| 23 | funccount. |
| 24 | |
| 25 | |
| 26 | The -v option includes more fields, including the on-CPU process (COMM and PID): |
| 27 | |
Vicent Marti | 592414e | 2016-03-27 18:22:03 +0200 | [diff] [blame] | 28 | # ./stacksnoop -v submit_bio |
| 29 | TIME(s) COMM PID CPU SYSCALL |
| 30 | 3734.855027000 jbd2/dm-0-8 313 0 submit_bio |
Sasha Goldshtein | 2bf3ff3 | 2017-02-08 23:25:00 -0500 | [diff] [blame] | 31 | submit_bio |
| 32 | submit_bh |
| 33 | jbd2_journal_commit_transaction |
| 34 | kjournald2 |
| 35 | kthread |
| 36 | ret_from_fork |
Brendan Gregg | 38cef48 | 2016-01-15 17:26:30 -0800 | [diff] [blame] | 37 | |
Vicent Marti | 592414e | 2016-03-27 18:22:03 +0200 | [diff] [blame] | 38 | This identifies the application issuing the sync syscall: the jbd2 process |
Brendan Gregg | 38cef48 | 2016-01-15 17:26:30 -0800 | [diff] [blame] | 39 | (COMM column). |
| 40 | |
| 41 | |
| 42 | Here's another example, showing the path to second_overflow() and on-CPU |
| 43 | process: |
| 44 | |
| 45 | # ./stacksnoop -v second_overflow |
Vicent Marti | 592414e | 2016-03-27 18:22:03 +0200 | [diff] [blame] | 46 | TIME(s) COMM PID CPU SYSCALL |
| 47 | 3837.526433000 <idle> 0 1 second_overflow |
Sasha Goldshtein | 2bf3ff3 | 2017-02-08 23:25:00 -0500 | [diff] [blame] | 48 | second_overflow |
| 49 | tick_do_update_jiffies64 |
| 50 | tick_irq_enter |
| 51 | irq_enter |
| 52 | smp_apic_timer_interrupt |
| 53 | apic_timer_interrupt |
| 54 | default_idle |
| 55 | arch_cpu_idle |
| 56 | default_idle_call |
| 57 | cpu_startup_entry |
| 58 | start_secondary |
Vicent Marti | 592414e | 2016-03-27 18:22:03 +0200 | [diff] [blame] | 59 | |
| 60 | 3838.526953000 <idle> 0 1 second_overflow |
Sasha Goldshtein | 2bf3ff3 | 2017-02-08 23:25:00 -0500 | [diff] [blame] | 61 | second_overflow |
| 62 | tick_do_update_jiffies64 |
| 63 | tick_irq_enter |
| 64 | irq_enter |
| 65 | smp_apic_timer_interrupt |
| 66 | apic_timer_interrupt |
| 67 | default_idle |
| 68 | arch_cpu_idle |
| 69 | default_idle_call |
| 70 | cpu_startup_entry |
| 71 | start_secondary |
Brendan Gregg | 38cef48 | 2016-01-15 17:26:30 -0800 | [diff] [blame] | 72 | |
| 73 | This fires every second (see TIME(s)), and is from tick_do_update_jiffies64(). |
| 74 | |
| 75 | |
| 76 | USAGE message: |
| 77 | |
| 78 | # ./stacksnoop -h |
| 79 | usage: stacksnoop [-h] [-p PID] [-s] [-v] function |
| 80 | |
| 81 | Trace and print kernel stack traces for a kernel function |
| 82 | |
| 83 | positional arguments: |
| 84 | function kernel function name |
| 85 | |
| 86 | optional arguments: |
| 87 | -h, --help show this help message and exit |
| 88 | -p PID, --pid PID trace this PID only |
| 89 | -s, --offset show address offsets |
| 90 | -v, --verbose print more fields |
| 91 | |
| 92 | examples: |
| 93 | ./stacksnoop ext4_sync_fs # print kernel stack traces for ext4_sync_fs |
| 94 | ./stacksnoop -s ext4_sync_fs # ... also show symbol offsets |
| 95 | ./stacksnoop -v ext4_sync_fs # ... show extra columns |
| 96 | ./stacksnoop -p 185 ext4_sync_fs # ... only when PID 185 is on-CPU |