xref: /aosp_15_r20/external/bcc/tools/funcslower_example.txt (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1*387f9dfdSAndroid Build Coastguard WorkerDemonstrations of funcslower, the Linux eBPF/bcc version.
2*387f9dfdSAndroid Build Coastguard Worker
3*387f9dfdSAndroid Build Coastguard Worker
4*387f9dfdSAndroid Build Coastguard Workerfuncslower shows kernel or user function invocations slower than a threshold.
5*387f9dfdSAndroid Build Coastguard WorkerThis can be used for last-resort diagnostics when aggregation-based tools have
6*387f9dfdSAndroid Build Coastguard Workerfailed. For example, trace the open() function in libc when it is slower than
7*387f9dfdSAndroid Build Coastguard Worker1 microsecond (us):
8*387f9dfdSAndroid Build Coastguard Worker
9*387f9dfdSAndroid Build Coastguard Worker# ./funcslower c:open -u 1
10*387f9dfdSAndroid Build Coastguard WorkerTracing function calls slower than 1 us... Ctrl+C to quit.
11*387f9dfdSAndroid Build Coastguard WorkerCOMM           PID    LAT(us)             RVAL FUNC
12*387f9dfdSAndroid Build Coastguard Workerless           27074    33.77                3 c:open
13*387f9dfdSAndroid Build Coastguard Workerless           27074     9.96 ffffffffffffffff c:open
14*387f9dfdSAndroid Build Coastguard Workerless           27074     5.92 ffffffffffffffff c:open
15*387f9dfdSAndroid Build Coastguard Workerless           27074    15.88 ffffffffffffffff c:open
16*387f9dfdSAndroid Build Coastguard Workerless           27074     8.89                3 c:open
17*387f9dfdSAndroid Build Coastguard Workerless           27074    15.89                3 c:open
18*387f9dfdSAndroid Build Coastguard Workersh             27075    20.97                4 c:open
19*387f9dfdSAndroid Build Coastguard Workerbash           27075    20.14                4 c:open
20*387f9dfdSAndroid Build Coastguard Workerlesspipe.sh    27075    18.77                4 c:open
21*387f9dfdSAndroid Build Coastguard Workerlesspipe.sh    27075    11.21                4 c:open
22*387f9dfdSAndroid Build Coastguard Workerlesspipe.sh    27075    13.68                4 c:open
23*387f9dfdSAndroid Build Coastguard Workerfile           27076    14.83 ffffffffffffffff c:open
24*387f9dfdSAndroid Build Coastguard Workerfile           27076     8.02                4 c:open
25*387f9dfdSAndroid Build Coastguard Workerfile           27076    10.26                4 c:open
26*387f9dfdSAndroid Build Coastguard Workerfile           27076     6.55                4 c:open
27*387f9dfdSAndroid Build Coastguard Workerless           27074    11.67                4 c:open
28*387f9dfdSAndroid Build Coastguard Worker^C
29*387f9dfdSAndroid Build Coastguard Worker
30*387f9dfdSAndroid Build Coastguard WorkerThis shows several open operations performed by less and some helpers it invoked
31*387f9dfdSAndroid Build Coastguard Workerin the process. The latency (in microseconds) is shown, as well as the return
32*387f9dfdSAndroid Build Coastguard Workervalue from the open() function, which helps indicate if there is a correlation
33*387f9dfdSAndroid Build Coastguard Workerbetween failures and slow invocations. Most open() calls seemed to have
34*387f9dfdSAndroid Build Coastguard Workercompleted successfully (returning a valid file descriptor), but some have failed
35*387f9dfdSAndroid Build Coastguard Workerand returned -1.
36*387f9dfdSAndroid Build Coastguard Worker
37*387f9dfdSAndroid Build Coastguard WorkerYou can also trace kernel functions:
38*387f9dfdSAndroid Build Coastguard Worker
39*387f9dfdSAndroid Build Coastguard Worker# ./funcslower -m 10 vfs_read
40*387f9dfdSAndroid Build Coastguard WorkerTracing function calls slower than 10 ms... Ctrl+C to quit.
41*387f9dfdSAndroid Build Coastguard WorkerCOMM           PID    LAT(ms)             RVAL FUNC
42*387f9dfdSAndroid Build Coastguard Workerbash           11527    78.97                1 vfs_read
43*387f9dfdSAndroid Build Coastguard Workerbash           11527   101.26                1 vfs_read
44*387f9dfdSAndroid Build Coastguard Workerbash           11527  1053.60                1 vfs_read
45*387f9dfdSAndroid Build Coastguard Workerbash           11527    44.21                1 vfs_read
46*387f9dfdSAndroid Build Coastguard Workerbash           11527    79.50                1 vfs_read
47*387f9dfdSAndroid Build Coastguard Workerbash           11527    33.37                1 vfs_read
48*387f9dfdSAndroid Build Coastguard Workerbash           11527   112.17                1 vfs_read
49*387f9dfdSAndroid Build Coastguard Workerbash           11527   101.49                1 vfs_read
50*387f9dfdSAndroid Build Coastguard Worker^C
51*387f9dfdSAndroid Build Coastguard Worker
52*387f9dfdSAndroid Build Coastguard WorkerOccasionally, it is also useful to see the arguments passed to the functions.
53*387f9dfdSAndroid Build Coastguard WorkerThe raw hex values of the arguments are available when using the -a switch:
54*387f9dfdSAndroid Build Coastguard Worker
55*387f9dfdSAndroid Build Coastguard Worker# ./funcslower __kmalloc -a 2 -u 1
56*387f9dfdSAndroid Build Coastguard WorkerTracing function calls slower than 1 us... Ctrl+C to quit.
57*387f9dfdSAndroid Build Coastguard WorkerCOMM           PID    LAT(us)             RVAL FUNC ARGS
58*387f9dfdSAndroid Build Coastguard Workerkworker/0:2    27077     7.46 ffff90054f9f8e40 __kmalloc 0x98 0x1400000
59*387f9dfdSAndroid Build Coastguard Workerkworker/0:2    27077     6.84 ffff90054f9f8e40 __kmalloc 0x98 0x1400000
60*387f9dfdSAndroid Build Coastguard Workerbash           11527     6.87 ffff90054f9f8e40 __kmalloc 0x90 0x1408240
61*387f9dfdSAndroid Build Coastguard Workerbash           11527     1.15 ffff90054f9f8e40 __kmalloc 0x90 0x1408240
62*387f9dfdSAndroid Build Coastguard Workerbash           11527     1.15 ffff90055a1b8c00 __kmalloc 0x2c 0x1400240
63*387f9dfdSAndroid Build Coastguard Workerbash           11527     1.18 ffff90054b87d240 __kmalloc 0x1c 0x1400040
64*387f9dfdSAndroid Build Coastguard Workerbash           11527    10.59 ffff900546d60000 __kmalloc 0x10000 0x14082c0
65*387f9dfdSAndroid Build Coastguard Workerbash           11527     1.49 ffff90054fbd4c00 __kmalloc 0x280 0x15080c0
66*387f9dfdSAndroid Build Coastguard Workerbash           11527     1.00 ffff90054789b000 __kmalloc 0x800 0x15012c0
67*387f9dfdSAndroid Build Coastguard Workerbash           27128     3.47 ffff90057ca1a200 __kmalloc 0x150 0x1400240
68*387f9dfdSAndroid Build Coastguard Workerbash           27128     1.82 ffff90054fbd4c00 __kmalloc 0x230 0x14000c0
69*387f9dfdSAndroid Build Coastguard Workerbash           27128     1.17 ffff90054b87d5a0 __kmalloc 0x1c 0x14000c0
70*387f9dfdSAndroid Build Coastguard Workerperf           27128     4.81 ffff90054f9f8e40 __kmalloc 0x90 0x1408240
71*387f9dfdSAndroid Build Coastguard Workerperf           27128    24.71 ffff900566990000 __kmalloc 0x10000 0x14082c0
72*387f9dfdSAndroid Build Coastguard Worker^C
73*387f9dfdSAndroid Build Coastguard Worker
74*387f9dfdSAndroid Build Coastguard WorkerThis shows the first two arguments to __kmalloc -- the first one is the size
75*387f9dfdSAndroid Build Coastguard Workerof the requested allocation. The return value is also shown (null return values
76*387f9dfdSAndroid Build Coastguard Workerwould indicate a failure).
77*387f9dfdSAndroid Build Coastguard Worker
78*387f9dfdSAndroid Build Coastguard Worker# ./funcslower -U -m 30 '/usr/sbin/nginx:database_write'
79*387f9dfdSAndroid Build Coastguard WorkerTracing function calls slower than 30 ms... Ctrl+C to quit.
80*387f9dfdSAndroid Build Coastguard WorkerCOMM           PID    LAT(ms)             RVAL FUNC
81*387f9dfdSAndroid Build Coastguard Workernginx          1617     30.15                9 /usr/sbin/nginx:database_write
82*387f9dfdSAndroid Build Coastguard Worker    DataBaseProvider::setData(std::string const&, record_s&)
83*387f9dfdSAndroid Build Coastguard Worker    UserDataProvider::saveRecordData(RecordData const&)
84*387f9dfdSAndroid Build Coastguard Worker    RequestProcessor::writeResponse(int)
85*387f9dfdSAndroid Build Coastguard Worker    RequestProcessor::processRequest()
86*387f9dfdSAndroid Build Coastguard Worker    RequestRouter::processRequest(RequestWrapper*, ResponseWrapper*)
87*387f9dfdSAndroid Build Coastguard Worker    ngx_http_core_content_phase
88*387f9dfdSAndroid Build Coastguard Worker    ngx_http_core_run_phases
89*387f9dfdSAndroid Build Coastguard Worker    ngx_http_process_request
90*387f9dfdSAndroid Build Coastguard Worker    ngx_process_events_and_timers
91*387f9dfdSAndroid Build Coastguard Worker    ngx_spawn_process
92*387f9dfdSAndroid Build Coastguard Worker    ngx_master_process_cycle
93*387f9dfdSAndroid Build Coastguard Worker    main
94*387f9dfdSAndroid Build Coastguard Worker    __libc_start_main
95*387f9dfdSAndroid Build Coastguard Worker    [unknown]
96*387f9dfdSAndroid Build Coastguard Workernginx          1629     30.14                9 /usr/sbin/nginx:database_write
97*387f9dfdSAndroid Build Coastguard Worker    DataBaseProvider::setData(std::string const&, record_s&)
98*387f9dfdSAndroid Build Coastguard Worker    UserDataProvider::saveRecordData(RecordData const&)
99*387f9dfdSAndroid Build Coastguard Worker    RequestProcessor::writeResponse(int)
100*387f9dfdSAndroid Build Coastguard Worker    RequestProcessor::processRequest()
101*387f9dfdSAndroid Build Coastguard Worker    RequestRouter::processRequest(RequestWrapper*, ResponseWrapper*)
102*387f9dfdSAndroid Build Coastguard Worker    ngx_http_core_content_phase
103*387f9dfdSAndroid Build Coastguard Worker    ngx_http_core_run_phases
104*387f9dfdSAndroid Build Coastguard Worker    ngx_http_process_request
105*387f9dfdSAndroid Build Coastguard Worker    ngx_process_events_and_timers
106*387f9dfdSAndroid Build Coastguard Worker    ngx_spawn_process
107*387f9dfdSAndroid Build Coastguard Worker    ngx_master_process_cycle
108*387f9dfdSAndroid Build Coastguard Worker    main
109*387f9dfdSAndroid Build Coastguard Worker    __libc_start_main
110*387f9dfdSAndroid Build Coastguard Worker    [unknown]
111*387f9dfdSAndroid Build Coastguard Worker^C
112*387f9dfdSAndroid Build Coastguard Worker
113*387f9dfdSAndroid Build Coastguard WorkerShows the user space stack trace of calls to the user space function call open taking longer than 30 ms.
114*387f9dfdSAndroid Build Coastguard Worker
115*387f9dfdSAndroid Build Coastguard WorkerUSAGE message:
116*387f9dfdSAndroid Build Coastguard Worker
117*387f9dfdSAndroid Build Coastguard Workerusage: funcslower.py [-hf] [-p PID] [-U | -K] [-m MIN_MS] [-u MIN_US] [-a ARGUMENTS] [-T]
118*387f9dfdSAndroid Build Coastguard Worker                     [-t] [-v]
119*387f9dfdSAndroid Build Coastguard Worker                     function [function ...]
120*387f9dfdSAndroid Build Coastguard Worker
121*387f9dfdSAndroid Build Coastguard WorkerTrace slow kernel or user function calls.
122*387f9dfdSAndroid Build Coastguard Worker
123*387f9dfdSAndroid Build Coastguard Workerpositional arguments:
124*387f9dfdSAndroid Build Coastguard Worker  function              function(s) to trace
125*387f9dfdSAndroid Build Coastguard Worker
126*387f9dfdSAndroid Build Coastguard Workeroptional arguments:
127*387f9dfdSAndroid Build Coastguard Worker  -h, --help            show this help message and exit
128*387f9dfdSAndroid Build Coastguard Worker  -p PID, --pid PID     trace this PID only
129*387f9dfdSAndroid Build Coastguard Worker  -m MIN_MS, --min-ms MIN_MS
130*387f9dfdSAndroid Build Coastguard Worker                        minimum duration to trace (ms)
131*387f9dfdSAndroid Build Coastguard Worker  -u MIN_US, --min-us MIN_US
132*387f9dfdSAndroid Build Coastguard Worker                        minimum duration to trace (us)
133*387f9dfdSAndroid Build Coastguard Worker  -U, --user-stack
134*387f9dfdSAndroid Build Coastguard Worker                        show stacks from user space
135*387f9dfdSAndroid Build Coastguard Worker  -K, --kernel-stack
136*387f9dfdSAndroid Build Coastguard Worker                        show stacks from kernel space
137*387f9dfdSAndroid Build Coastguard Worker  -f                    print output in folded stack format.
138*387f9dfdSAndroid Build Coastguard Worker  -a ARGUMENTS, --arguments ARGUMENTS
139*387f9dfdSAndroid Build Coastguard Worker                        print this many entry arguments, as hex
140*387f9dfdSAndroid Build Coastguard Worker  -T, --time            show HH:MM:SS timestamp
141*387f9dfdSAndroid Build Coastguard Worker  -t, --timestamp       show timestamp in seconds at us resolution
142*387f9dfdSAndroid Build Coastguard Worker  -v, --verbose         print the BPF program for debugging purposes
143*387f9dfdSAndroid Build Coastguard Worker
144*387f9dfdSAndroid Build Coastguard Workerexamples:
145*387f9dfdSAndroid Build Coastguard Worker  ./funcslower vfs_write       # trace vfs_write calls slower than 1ms
146*387f9dfdSAndroid Build Coastguard Worker  ./funcslower -m 10 vfs_write # same, but slower than 10ms
147*387f9dfdSAndroid Build Coastguard Worker  ./funcslower -u 10 c:open    # trace open calls slower than 10us
148*387f9dfdSAndroid Build Coastguard Worker  ./funcslower -p 135 c:open   # trace pid 135 only
149*387f9dfdSAndroid Build Coastguard Worker  ./funcslower c:malloc c:free # trace both malloc and free slower than 1ms
150*387f9dfdSAndroid Build Coastguard Worker  ./funcslower -a 2 c:open     # show first two arguments to open
151