blob: 5ee00786c2914a80726b7ec08c72b34b04d8722e [file] [log] [blame]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -08001Demonstrations of argdist.
Sasha Goldshtein4cd70632016-02-11 01:55:11 -08002
3
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -08004argdist probes functions you specify and collects parameter values into a
5histogram or a frequency count. This can be used to understand the distribution
Sasha Goldshtein4cd70632016-02-11 01:55:11 -08006of values a certain parameter takes, filter and print interesting parameters
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -08007without attaching a debugger, and obtain general execution statistics on
Sasha Goldshtein4cd70632016-02-11 01:55:11 -08008various functions.
9
10For example, suppose you want to find what allocation sizes are common in
11your application:
12
Sasha Goldshteind2f47622016-10-04 18:40:15 +030013# ./argdist -p 2420 -c -C 'p:c:malloc(size_t size):size_t:size'
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080014[01:42:29]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -080015p:c:malloc(size_t size):size_t:size
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080016 COUNT EVENT
17[01:42:30]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -080018p:c:malloc(size_t size):size_t:size
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080019 COUNT EVENT
20[01:42:31]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -080021p:c:malloc(size_t size):size_t:size
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080022 COUNT EVENT
23 1 size = 16
24[01:42:32]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -080025p:c:malloc(size_t size):size_t:size
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080026 COUNT EVENT
27 2 size = 16
28[01:42:33]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -080029p:c:malloc(size_t size):size_t:size
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080030 COUNT EVENT
31 3 size = 16
32[01:42:34]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -080033p:c:malloc(size_t size):size_t:size
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080034 COUNT EVENT
35 4 size = 16
36^C
37
38It seems that the application is allocating blocks of size 16. The COUNT
39column contains the number of occurrences of a particular event, and the
40EVENT column describes the event. In this case, the "size" parameter was
41probed and its value was 16, repeatedly.
42
43Now, suppose you wanted a histogram of buffer sizes passed to the write()
44function across the system:
45
Sasha Goldshteind2f47622016-10-04 18:40:15 +030046# ./argdist -c -H 'p:c:write(int fd, void *buf, size_t len):size_t:len'
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080047[01:45:22]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -080048p:c:write(int fd, void *buf, size_t len):size_t:len
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080049 len : count distribution
50 0 -> 1 : 0 | |
51 2 -> 3 : 2 |************* |
52 4 -> 7 : 0 | |
53 8 -> 15 : 2 |************* |
54 16 -> 31 : 0 | |
55 32 -> 63 : 6 |****************************************|
56[01:45:23]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -080057p:c:write(int fd, void *buf, size_t len):size_t:len
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080058 len : count distribution
59 0 -> 1 : 0 | |
60 2 -> 3 : 11 |*************** |
61 4 -> 7 : 0 | |
62 8 -> 15 : 4 |***** |
63 16 -> 31 : 0 | |
64 32 -> 63 : 28 |****************************************|
65 64 -> 127 : 12 |***************** |
66[01:45:24]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -080067p:c:write(int fd, void *buf, size_t len):size_t:len
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080068 len : count distribution
69 0 -> 1 : 0 | |
70 2 -> 3 : 21 |**************** |
71 4 -> 7 : 0 | |
72 8 -> 15 : 6 |**** |
73 16 -> 31 : 0 | |
74 32 -> 63 : 52 |****************************************|
75 64 -> 127 : 26 |******************** |
76^C
77
78It seems that most writes fall into three buckets: very small writes of 2-3
79bytes, medium writes of 32-63 bytes, and larger writes of 64-127 bytes.
80
81But these are writes across the board -- what if you wanted to focus on writes
82to STDOUT?
83
Sasha Goldshteind2f47622016-10-04 18:40:15 +030084# ./argdist -c -H 'p:c:write(int fd, void *buf, size_t len):size_t:len:fd==1'
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080085[01:47:17]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -080086p:c:write(int fd, void *buf, size_t len):size_t:len:fd==1
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080087 len : count distribution
88 0 -> 1 : 0 | |
89 2 -> 3 : 0 | |
90 4 -> 7 : 0 | |
91 8 -> 15 : 1 |****************************************|
92 16 -> 31 : 0 | |
93 32 -> 63 : 1 |****************************************|
94[01:47:18]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -080095p:c:write(int fd, void *buf, size_t len):size_t:len:fd==1
Sasha Goldshtein4cd70632016-02-11 01:55:11 -080096 len : count distribution
97 0 -> 1 : 0 | |
98 2 -> 3 : 0 | |
99 4 -> 7 : 0 | |
100 8 -> 15 : 2 |************* |
101 16 -> 31 : 0 | |
102 32 -> 63 : 3 |******************** |
103 64 -> 127 : 6 |****************************************|
104[01:47:19]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800105p:c:write(int fd, void *buf, size_t len):size_t:len:fd==1
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800106 len : count distribution
107 0 -> 1 : 0 | |
108 2 -> 3 : 0 | |
109 4 -> 7 : 0 | |
110 8 -> 15 : 3 |********* |
111 16 -> 31 : 0 | |
112 32 -> 63 : 5 |*************** |
113 64 -> 127 : 13 |****************************************|
114^C
115
116The "fd==1" part is a filter that is applied to every invocation of write().
117Only if the filter condition is true, the value is recorded.
118
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800119You can also use argdist to trace kernel functions. For example, suppose you
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800120wanted a histogram of kernel allocation (kmalloc) sizes across the system,
121printed twice with 3 second intervals:
122
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800123# ./argdist -i 3 -n 2 -H 'p::__kmalloc(size_t size):size_t:size'
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800124[01:50:00]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800125p::__kmalloc(size_t size):size_t:size
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800126 size : count distribution
127 0 -> 1 : 0 | |
128 2 -> 3 : 0 | |
129 4 -> 7 : 0 | |
130 8 -> 15 : 6 |****************************************|
131[01:50:03]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800132p::__kmalloc(size_t size):size_t:size
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800133 size : count distribution
134 0 -> 1 : 0 | |
135 2 -> 3 : 0 | |
136 4 -> 7 : 0 | |
137 8 -> 15 : 22 |****************************************|
138 16 -> 31 : 0 | |
139 32 -> 63 : 0 | |
140 64 -> 127 : 5 |********* |
141 128 -> 255 : 2 |*** |
142
143Occasionally, numeric information isn't enough and you want to capture strings.
144What are the strings printed by puts() across the system?
145
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800146# ./argdist -i 10 -n 1 -C 'p:c:puts(char *str):char*:str'
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800147[01:53:54]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800148p:c:puts(char *str):char*:str
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800149 COUNT EVENT
150 2 str = Press ENTER to start.
151
152It looks like the message "Press ENTER to start." was printed twice during the
15310 seconds we were tracing.
154
Sasha Goldshtein8058eb12016-02-11 02:17:22 -0800155What about reads? You could trace gets() across the system and print the
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800156strings input by the user (note how "r" is used instead of "p" to attach a
157probe to the function's return):
Sasha Goldshtein8058eb12016-02-11 02:17:22 -0800158
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800159# ./argdist -i 10 -n 1 -C 'r:c:gets():char*:(char*)$retval:$retval!=0'
Sasha Goldshtein8058eb12016-02-11 02:17:22 -0800160[02:12:23]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800161r:c:gets():char*:$retval:$retval!=0
Sasha Goldshtein8058eb12016-02-11 02:17:22 -0800162 COUNT EVENT
Sasha Goldshteincc27edf2016-02-14 03:49:01 -0800163 1 (char*)$retval = hi there
164 3 (char*)$retval = sasha
165 8 (char*)$retval = hello
Sasha Goldshtein8058eb12016-02-11 02:17:22 -0800166
167Similarly, we could get a histogram of the error codes returned by read():
168
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800169# ./argdist -i 10 -c 1 -H 'r:c:read()'
Sasha Goldshtein8058eb12016-02-11 02:17:22 -0800170[02:15:36]
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800171r:c:read()
172 retval : count distribution
Sasha Goldshtein8058eb12016-02-11 02:17:22 -0800173 0 -> 1 : 29 |****************************************|
174 2 -> 3 : 11 |*************** |
175 4 -> 7 : 0 | |
176 8 -> 15 : 3 |**** |
177 16 -> 31 : 2 |** |
178 32 -> 63 : 22 |****************************** |
179 64 -> 127 : 5 |****** |
180 128 -> 255 : 0 | |
181 256 -> 511 : 1 |* |
182 512 -> 1023 : 1 |* |
183 1024 -> 2047 : 0 | |
184 2048 -> 4095 : 2 |** |
185
Sasha Goldshteine3501152016-02-13 03:56:29 -0800186In return probes, you can also trace the latency of the function (unless it is
187recursive) and the parameters it had on entry. For example, we can identify
188which processes are performing slow synchronous filesystem reads -- say,
189longer than 0.1ms (100,000ns):
190
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800191# ./argdist -C 'r::__vfs_read():u32:$PID:$latency > 100000'
Sasha Goldshteine3501152016-02-13 03:56:29 -0800192[01:08:48]
193r::__vfs_read():u32:$PID:$latency > 100000
194 COUNT EVENT
Sasha Goldshteincc27edf2016-02-14 03:49:01 -0800195 1 $PID = 10457
196 21 $PID = 2780
Sasha Goldshteine3501152016-02-13 03:56:29 -0800197[01:08:49]
198r::__vfs_read():u32:$PID:$latency > 100000
199 COUNT EVENT
Sasha Goldshteincc27edf2016-02-14 03:49:01 -0800200 1 $PID = 10457
201 21 $PID = 2780
Sasha Goldshteine3501152016-02-13 03:56:29 -0800202^C
203
Sasha Goldshteincc27edf2016-02-14 03:49:01 -0800204It looks like process 2780 performed 21 slow reads.
Sasha Goldshteine3501152016-02-13 03:56:29 -0800205
206Occasionally, entry parameter values are also interesting. For example, you
207might be curious how long it takes malloc() to allocate memory -- nanoseconds
208per byte allocated. Let's go:
209
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800210# ./argdist -H 'r:c:malloc(size_t size):u64:$latency/$entry(size);ns per byte' -n 1 -i 10
Sasha Goldshteine3501152016-02-13 03:56:29 -0800211[01:11:13]
212 ns per byte : count distribution
213 0 -> 1 : 0 | |
214 2 -> 3 : 4 |***************** |
215 4 -> 7 : 3 |************* |
216 8 -> 15 : 2 |******** |
217 16 -> 31 : 1 |**** |
218 32 -> 63 : 0 | |
219 64 -> 127 : 7 |******************************* |
220 128 -> 255 : 1 |**** |
221 256 -> 511 : 0 | |
222 512 -> 1023 : 1 |**** |
223 1024 -> 2047 : 1 |**** |
224 2048 -> 4095 : 9 |****************************************|
225 4096 -> 8191 : 1 |**** |
226
227It looks like a tri-modal distribution. Some allocations are extremely cheap,
228and take 2-15 nanoseconds per byte. Other allocations are slower, and take
22964-127 nanoseconds per byte. And some allocations are slower still, and take
230multiple microseconds per byte.
231
Sasha Goldshteincc27edf2016-02-14 03:49:01 -0800232You could also group results by more than one field. For example, __kmalloc
233takes an additional flags parameter that describes how to allocate memory:
234
Sasha Goldshteind2f47622016-10-04 18:40:15 +0300235# ./argdist -c -C 'p::__kmalloc(size_t size, gfp_t flags):gfp_t,size_t:flags,size'
Sasha Goldshteincc27edf2016-02-14 03:49:01 -0800236[03:42:29]
237p::__kmalloc(size_t size, gfp_t flags):gfp_t,size_t:flags,size
238 COUNT EVENT
239 1 flags = 16, size = 152
240 2 flags = 131280, size = 8
241 7 flags = 131280, size = 16
242[03:42:30]
243p::__kmalloc(size_t size, gfp_t flags):gfp_t,size_t:flags,size
244 COUNT EVENT
245 1 flags = 16, size = 152
246 6 flags = 131280, size = 8
247 19 flags = 131280, size = 16
248[03:42:31]
249p::__kmalloc(size_t size, gfp_t flags):gfp_t,size_t:flags,size
250 COUNT EVENT
251 2 flags = 16, size = 152
252 10 flags = 131280, size = 8
253 31 flags = 131280, size = 16
254[03:42:32]
255p::__kmalloc(size_t size, gfp_t flags):gfp_t,size_t:flags,size
256 COUNT EVENT
257 2 flags = 16, size = 152
258 14 flags = 131280, size = 8
259 43 flags = 131280, size = 16
260^C
261
262The flags value must be expanded by hand, but it's still helpful to eliminate
263certain kinds of allocations or visually group them together.
264
Sasha Goldshteinfd60d552016-03-01 12:15:34 -0800265argdist also has basic support for kernel tracepoints. It is sometimes more
266convenient to use tracepoints because they are documented and don't vary a lot
Sasha Goldshtein376ae5c2016-10-04 19:49:57 +0300267between kernel versions. For example, let's trace the net:net_dev_start_xmit
268tracepoint and print out the protocol field from the tracepoint structure:
Sasha Goldshteinfd60d552016-03-01 12:15:34 -0800269
Sasha Goldshtein376ae5c2016-10-04 19:49:57 +0300270# argdist -C 't:net:net_dev_start_xmit():u16:args->protocol'
271[13:01:49]
272t:net:net_dev_start_xmit():u16:args->protocol
Sasha Goldshteinfd60d552016-03-01 12:15:34 -0800273 COUNT EVENT
Sasha Goldshtein376ae5c2016-10-04 19:49:57 +0300274 8 args->protocol = 2048
275^C
Sasha Goldshteinfd60d552016-03-01 12:15:34 -0800276
Sasha Goldshtein376ae5c2016-10-04 19:49:57 +0300277Note that to discover the format of the net:net_dev_start_xmit tracepoint, you
278use the tplist tool (tplist -v net:net_dev_start_xmit).
Sasha Goldshteinfd60d552016-03-01 12:15:34 -0800279
Sasha Goldshteinc8f752f2016-10-17 02:18:43 -0700280
281Occasionally, it is useful to filter certain expressions by string. This is not
282trivially supported by BPF, but argdist provides a STRCMP helper you can use in
283filter expressions. For example, to get a histogram of latencies opening a
284specific file, run this:
285
286# argdist -c -H 'r:c:open(char *file):u64:$latency/1000:STRCMP("test.txt",$entry(file))'
287[02:16:38]
288[02:16:39]
289[02:16:40]
290 $latency/1000 : count distribution
291 0 -> 1 : 0 | |
292 2 -> 3 : 0 | |
293 4 -> 7 : 0 | |
294 8 -> 15 : 0 | |
295 16 -> 31 : 2 |****************************************|
296[02:16:41]
297 $latency/1000 : count distribution
298 0 -> 1 : 0 | |
299 2 -> 3 : 0 | |
300 4 -> 7 : 0 | |
301 8 -> 15 : 1 |********** |
302 16 -> 31 : 4 |****************************************|
303[02:16:42]
304 $latency/1000 : count distribution
305 0 -> 1 : 0 | |
306 2 -> 3 : 0 | |
307 4 -> 7 : 0 | |
308 8 -> 15 : 1 |******** |
309 16 -> 31 : 5 |****************************************|
310[02:16:43]
311 $latency/1000 : count distribution
312 0 -> 1 : 0 | |
313 2 -> 3 : 0 | |
314 4 -> 7 : 0 | |
315 8 -> 15 : 1 |******** |
316 16 -> 31 : 5 |****************************************|
317
318
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800319Here's a final example that finds how many write() system calls are performed
320by each process on the system:
321
Sasha Goldshteind2f47622016-10-04 18:40:15 +0300322# argdist -c -C 'p:c:write():int:$PID;write per process' -n 2
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800323[06:47:18]
324write by process
325 COUNT EVENT
Sasha Goldshteincc27edf2016-02-14 03:49:01 -0800326 3 $PID = 8889
327 7 $PID = 7615
328 7 $PID = 2480
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800329[06:47:19]
330write by process
331 COUNT EVENT
Sasha Goldshteincc27edf2016-02-14 03:49:01 -0800332 9 $PID = 8889
333 23 $PID = 7615
334 23 $PID = 2480
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800335
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800336
337USAGE message:
338
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800339# argdist -h
340usage: argdist [-h] [-p PID] [-z STRING_SIZE] [-i INTERVAL] [-n COUNT] [-v]
Sasha Goldshtein4725a722016-10-18 20:54:47 +0300341 [-c] [-T TOP] [-H specifier] [-C[specifier] [-I header]
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800342
343Trace a function and display a summary of its parameter values.
344
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800345optional arguments:
346 -h, --help show this help message and exit
347 -p PID, --pid PID id of the process to trace (optional)
zhenwei pi66773212021-09-06 18:28:16 +0800348 -t TID, --tid TID id of the thread to trace (optional)
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800349 -z STRING_SIZE, --string-size STRING_SIZE
350 maximum string size to read from char* arguments
Sasha Goldshtein0a9783b2016-02-11 11:21:01 -0800351 -i INTERVAL, --interval INTERVAL
Akilesh Kailash89967192018-05-18 13:36:54 -0700352 output interval, in seconds (default 1 second)
353 -d DURATION, --duration DURATION
354 total duration of trace, in seconds
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800355 -n COUNT, --number COUNT
Sasha Goldshtein0a9783b2016-02-11 11:21:01 -0800356 number of outputs
Sasha Goldshteine3501152016-02-13 03:56:29 -0800357 -v, --verbose print resulting BPF program code before executing
Sasha Goldshteind2f47622016-10-04 18:40:15 +0300358 -c, --cumulative do not clear histograms and freq counts at each interval
Sasha Goldshteine3501152016-02-13 03:56:29 -0800359 -T TOP, --top TOP number of top results to show (not applicable to
360 histograms)
Sasha Goldshtein4725a722016-10-18 20:54:47 +0300361 -H specifier, --histogram specifier
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800362 probe specifier to capture histogram of (see examples
363 below)
Sasha Goldshtein4725a722016-10-18 20:54:47 +0300364 -C specifier, --count specifier
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800365 probe specifier to capture count of (see examples
366 below)
Sasha Goldshtein4725a722016-10-18 20:54:47 +0300367 -I header, --include header
Sasha Goldshtein7983d6b2016-02-13 23:14:18 -0800368 additional header files to include in the BPF program
Yonghong Songf4470dc2017-12-13 14:12:13 -0800369 as either full path, or relative to current working directory,
370 or relative to default kernel header search path
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800371
372Probe specifier syntax:
Sasha Goldshtein3e39a082016-03-24 08:39:47 -0700373 {p,r,t,u}:{[library],category}:function(signature)[:type[,type...]:expr[,expr...][:filter]][#label]
Sasha Goldshtein8058eb12016-02-11 02:17:22 -0800374Where:
Sasha Goldshtein3e39a082016-03-24 08:39:47 -0700375 p,r,t,u -- probe at function entry, function exit, kernel tracepoint,
376 or USDT probe
Sasha Goldshteine3501152016-02-13 03:56:29 -0800377 in exit probes: can use $retval, $entry(param), $latency
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800378 library -- the library that contains the function
379 (leave empty for kernel functions)
Sasha Goldshteinfd60d552016-03-01 12:15:34 -0800380 category -- the category of the kernel tracepoint (e.g. net, sched)
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800381 signature -- the function's parameters, as in the C header
Sasha Goldshteincc27edf2016-02-14 03:49:01 -0800382 type -- the type of the expression to collect (supports multiple)
383 expr -- the expression to collect (supports multiple)
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800384 filter -- the filter that is applied to collected values
385 label -- the label for this probe in the resulting output
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800386
387EXAMPLES:
388
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800389argdist -H 'p::__kmalloc(u64 size):u64:size'
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800390 Print a histogram of allocation sizes passed to kmalloc
391
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800392argdist -p 1005 -C 'p:c:malloc(size_t size):size_t:size:size==16'
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800393 Print a frequency count of how many times process 1005 called malloc
394 with an allocation size of 16 bytes
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800395
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800396argdist -C 'r:c:gets():char*:$retval#snooped strings'
Sasha Goldshtein8058eb12016-02-11 02:17:22 -0800397 Snoop on all strings returned by gets()
398
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800399argdist -H 'r::__kmalloc(size_t size):u64:$latency/$entry(size)#ns per byte'
Sasha Goldshteine3501152016-02-13 03:56:29 -0800400 Print a histogram of nanoseconds per byte from kmalloc allocations
401
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800402argdist -C 'p::__kmalloc(size_t size, gfp_t flags):size_t:size:flags&GFP_ATOMIC'
Sasha Goldshtein7983d6b2016-02-13 23:14:18 -0800403 Print frequency count of kmalloc allocation sizes that have GFP_ATOMIC
404
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800405argdist -p 1005 -C 'p:c:write(int fd):int:fd' -T 5
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800406 Print frequency counts of how many times writes were issued to a
Sasha Goldshteine3501152016-02-13 03:56:29 -0800407 particular file descriptor number, in process 1005, but only show
408 the top 5 busiest fds
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800409
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800410argdist -p 1005 -H 'r:c:read()'
Sasha Goldshtein8058eb12016-02-11 02:17:22 -0800411 Print a histogram of error codes returned by read() in process 1005
412
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800413argdist -C 'r::__vfs_read():u32:$PID:$latency > 100000'
Sasha Goldshteine3501152016-02-13 03:56:29 -0800414 Print frequency of reads by process where the latency was >0.1ms
415
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800416argdist -H 'r::__vfs_read(void *file, void *buf, size_t count):size_t:$entry(count):$latency > 1000000'
Sasha Goldshteine3501152016-02-13 03:56:29 -0800417 Print a histogram of read sizes that were longer than 1ms
418
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800419argdist -H \
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800420 'p:c:write(int fd, const void *buf, size_t count):size_t:count:fd==1'
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800421 Print a histogram of buffer sizes passed to write() across all
422 processes, where the file descriptor was 1 (STDOUT)
423
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800424argdist -C 'p:c:fork()#fork calls'
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800425 Count fork() calls in libc across all processes
Sasha Goldshteine3501152016-02-13 03:56:29 -0800426 Can also use funccount.py, which is easier and more flexible
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800427
Sasha Goldshtein376ae5c2016-10-04 19:49:57 +0300428argdist -H 't:block:block_rq_complete():u32:args->nr_sector'
Sasha Goldshteinfd60d552016-03-01 12:15:34 -0800429 Print histogram of number of sectors in completing block I/O requests
430
Sasha Goldshtein376ae5c2016-10-04 19:49:57 +0300431argdist -C 't:irq:irq_handler_entry():int:args->irq'
Sasha Goldshteinfd60d552016-03-01 12:15:34 -0800432 Aggregate interrupts by interrupt request (IRQ)
433
Sasha Goldshtein3e39a082016-03-24 08:39:47 -0700434argdist -C 'u:pthread:pthread_start():u64:arg2' -p 1337
435 Print frequency of function addresses used as a pthread start function,
436 relying on the USDT pthread_start probe in process 1337
437
Sasha Goldshtein4725a722016-10-18 20:54:47 +0300438argdist -H 'p:c:sleep(u32 seconds):u32:seconds' \
439 -H 'p:c:nanosleep(struct timespec *req):long:req->tv_nsec'
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800440 Print histograms of sleep() and nanosleep() parameter values
441
Sasha Goldshtein7df65da2016-02-14 05:12:27 -0800442argdist -p 2780 -z 120 \
Sasha Goldshtein5e4e1f42016-02-12 06:52:19 -0800443 -C 'p:c:write(int fd, char* buf, size_t len):char*:buf:fd==1'
Sasha Goldshtein4cd70632016-02-11 01:55:11 -0800444 Spy on writes to STDOUT performed by process 2780, up to a string size
Sasha Goldshteine3501152016-02-13 03:56:29 -0800445 of 120 characters
Yonghong Songf4470dc2017-12-13 14:12:13 -0800446
447argdist -I 'kernel/sched/sched.h' \
448 -C 'p::__account_cfs_rq_runtime(struct cfs_rq *cfs_rq):s64:cfs_rq->runtime_remaining'
449 Trace on the cfs scheduling runqueue remaining runtime. The struct cfs_rq is defined
450 in kernel/sched/sched.h which is in kernel source tree and not in kernel-devel
451 package. So this command needs to run at the kernel source tree root directory
452 so that the added header file can be found by the compiler.
Sumanth Korikkar306080b2020-04-27 04:37:23 -0500453
454argdist -C 'p::do_sys_open(int dfd, const char __user *filename, int flags,
455 umode_t mode):char*:filename:STRCMP("sample.txt", filename)'
456 Trace open of the file "sample.txt". It should be noted that 'filename'
457 passed to the do_sys_open is a char * user pointer. Hence parameter
458 'filename' should be tagged with __user for kprobes (const char __user
459 *filename). This information distinguishes if the 'filename' should be
460 copied from userspace to the bpf stack or from kernel space to the bpf
461 stack.