]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - Documentation/trace/histogram.rst
UBUNTU: Ubuntu-5.15.0-39.42
[mirror_ubuntu-jammy-kernel.git] / Documentation / trace / histogram.rst
CommitLineData
ea272257
MCC
1================
2Event Histograms
3================
b8df4a36 4
ea272257 5Documentation written by Tom Zanussi
b8df4a36
TZ
6
71. Introduction
8===============
9
10 Histogram triggers are special event triggers that can be used to
11 aggregate trace event data into histograms. For information on
5fb94e9c 12 trace events and event triggers, see Documentation/trace/events.rst.
b8df4a36
TZ
13
14
152. Histogram Trigger Command
16============================
17
18 A histogram trigger command is an event trigger command that
19 aggregates event hits into a hash table keyed on one or more trace
20 event format fields (or stacktrace) and a set of running totals
21 derived from one or more trace event format fields and/or event
22 counts (hitcount).
23
ea272257 24 The format of a hist trigger is as follows::
b8df4a36
TZ
25
26 hist:keys=<field1[,field2,...]>[:values=<field1[,field2,...]>]
27 [:sort=<field1[,field2,...]>][:size=#entries][:pause][:continue]
5032b381 28 [:clear][:name=histname1][:<handler>.<action>] [if <filter>]
b8df4a36
TZ
29
30 When a matching event is hit, an entry is added to a hash table
31 using the key(s) and value(s) named. Keys and values correspond to
32 fields in the event's format description. Values must correspond to
33 numeric fields - on an event hit, the value(s) will be added to a
34 sum kept for that field. The special string 'hitcount' can be used
35 in place of an explicit value field - this is simply a count of
36 event hits. If 'values' isn't specified, an implicit 'hitcount'
37 value will be automatically created and used as the only value.
38 Keys can be any field, or the special string 'stacktrace', which
39 will use the event's kernel stacktrace as the key. The keywords
40 'keys' or 'key' can be used to specify keys, and the keywords
41 'values', 'vals', or 'val' can be used to specify values. Compound
42 keys consisting of up to two fields can be specified by the 'keys'
43 keyword. Hashing a compound key produces a unique entry in the
44 table for each unique combination of component keys, and can be
45 useful for providing more fine-grained summaries of event data.
46 Additionally, sort keys consisting of up to two fields can be
47 specified by the 'sort' keyword. If more than one field is
48 specified, the result will be a 'sort within a sort': the first key
49 is taken to be the primary sort key and the second the secondary
50 key. If a hist trigger is given a name using the 'name' parameter,
51 its histogram data will be shared with other triggers of the same
52 name, and trigger hits will update this common data. Only triggers
53 with 'compatible' fields can be combined in this way; triggers are
54 'compatible' if the fields named in the trigger share the same
55 number and type of fields and those fields also have the same names.
56 Note that any two events always share the compatible 'hitcount' and
57 'stacktrace' fields and can therefore be combined using those
58 fields, however pointless that may be.
59
60 'hist' triggers add a 'hist' file to each event's subdirectory.
61 Reading the 'hist' file for the event will dump the hash table in
62 its entirety to stdout. If there are multiple hist triggers
63 attached to an event, there will be a table for each trigger in the
64 output. The table displayed for a named trigger will be the same as
65 any other instance having the same name. Each printed hash table
66 entry is a simple list of the keys and values comprising the entry;
67 keys are printed first and are delineated by curly braces, and are
68 followed by the set of value fields for the entry. By default,
69 numeric fields are displayed as base-10 integers. This can be
70 modified by appending any of the following modifiers to the field
71 name:
72
4420f5b1
SRV
73 ============= =================================================
74 .hex display a number as a hex value
75 .sym display an address as a symbol
76 .sym-offset display an address as a symbol and offset
77 .syscall display a syscall id as a system call name
78 .execname display a common_pid as a program name
79 .log2 display log2 value rather than raw number
37036435 80 .buckets=size display grouping of values rather than raw number
4420f5b1
SRV
81 .usecs display a common_timestamp in microseconds
82 ============= =================================================
b8df4a36
TZ
83
84 Note that in general the semantics of a given field aren't
85 interpreted when applying a modifier to it, but there are some
86 restrictions to be aware of in this regard:
87
88 - only the 'hex' modifier can be used for values (because values
89 are essentially sums, and the other modifiers don't make sense
90 in that context).
91 - the 'execname' modifier can only be used on a 'common_pid'. The
92 reason for this is that the execname is simply the 'comm' value
93 saved for the 'current' process when an event was triggered,
94 which is the same as the common_pid value saved by the event
95 tracing code. Trying to apply that comm value to other pid
96 values wouldn't be correct, and typically events that care save
97 pid-specific comm fields in the event itself.
98
99 A typical usage scenario would be the following to enable a hist
ea272257 100 trigger, read its current contents, and then turn it off::
b8df4a36 101
ea272257
MCC
102 # echo 'hist:keys=skbaddr.hex:vals=len' > \
103 /sys/kernel/debug/tracing/events/net/netif_rx/trigger
b8df4a36 104
ea272257 105 # cat /sys/kernel/debug/tracing/events/net/netif_rx/hist
b8df4a36 106
ea272257
MCC
107 # echo '!hist:keys=skbaddr.hex:vals=len' > \
108 /sys/kernel/debug/tracing/events/net/netif_rx/trigger
b8df4a36
TZ
109
110 The trigger file itself can be read to show the details of the
111 currently attached hist trigger. This information is also displayed
112 at the top of the 'hist' file when read.
113
114 By default, the size of the hash table is 2048 entries. The 'size'
115 parameter can be used to specify more or fewer than that. The units
116 are in terms of hashtable entries - if a run uses more entries than
117 specified, the results will show the number of 'drops', the number
118 of hits that were ignored. The size should be a power of 2 between
119 128 and 131072 (any non- power-of-2 number specified will be rounded
120 up).
121
122 The 'sort' parameter can be used to specify a value field to sort
123 on. The default if unspecified is 'hitcount' and the default sort
124 order is 'ascending'. To sort in the opposite direction, append
125 .descending' to the sort key.
126
127 The 'pause' parameter can be used to pause an existing hist trigger
128 or to start a hist trigger but not log any events until told to do
129 so. 'continue' or 'cont' can be used to start or restart a paused
130 hist trigger.
131
132 The 'clear' parameter will clear the contents of a running hist
133 trigger and leave its current paused/active state.
134
135 Note that the 'pause', 'cont', and 'clear' parameters should be
136 applied using 'append' shell operator ('>>') if applied to an
137 existing trigger, rather than via the '>' operator, which will cause
138 the trigger to be removed through truncation.
139
140- enable_hist/disable_hist
141
142 The enable_hist and disable_hist triggers can be used to have one
143 event conditionally start and stop another event's already-attached
144 hist trigger. Any number of enable_hist and disable_hist triggers
145 can be attached to a given event, allowing that event to kick off
146 and stop aggregations on a host of other events.
147
ea272257 148 The format is very similar to the enable/disable_event triggers::
b8df4a36
TZ
149
150 enable_hist:<system>:<event>[:count]
151 disable_hist:<system>:<event>[:count]
152
153 Instead of enabling or disabling the tracing of the target event
154 into the trace buffer as the enable/disable_event triggers do, the
155 enable/disable_hist triggers enable or disable the aggregation of
156 the target event into a hash table.
157
158 A typical usage scenario for the enable_hist/disable_hist triggers
159 would be to first set up a paused hist trigger on some event,
160 followed by an enable_hist/disable_hist pair that turns the hist
ea272257 161 aggregation on and off when conditions of interest are hit::
b8df4a36 162
ea272257
MCC
163 # echo 'hist:keys=skbaddr.hex:vals=len:pause' > \
164 /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
b8df4a36 165
ea272257
MCC
166 # echo 'enable_hist:net:netif_receive_skb if filename==/usr/bin/wget' > \
167 /sys/kernel/debug/tracing/events/sched/sched_process_exec/trigger
b8df4a36 168
ea272257
MCC
169 # echo 'disable_hist:net:netif_receive_skb if comm==wget' > \
170 /sys/kernel/debug/tracing/events/sched/sched_process_exit/trigger
b8df4a36
TZ
171
172 The above sets up an initially paused hist trigger which is unpaused
173 and starts aggregating events when a given program is executed, and
174 which stops aggregating when the process exits and the hist trigger
175 is paused again.
176
177 The examples below provide a more concrete illustration of the
178 concepts and typical usage patterns discussed above.
179
ea272257
MCC
180'special' event fields
181------------------------
8b7622bf
TZ
182
183 There are a number of 'special event fields' available for use as
184 keys or values in a hist trigger. These look like and behave as if
185 they were actual event fields, but aren't really part of the event's
186 field definition or format file. They are however available for any
187 event, and can be used anywhere an actual event field could be.
188 They are:
189
ea272257
MCC
190 ====================== ==== =======================================
191 common_timestamp u64 timestamp (from ring buffer) associated
192 with the event, in nanoseconds. May be
193 modified by .usecs to have timestamps
194 interpreted as microseconds.
1e3bac71 195 common_cpu int the cpu on which the event occurred.
ea272257 196 ====================== ==== =======================================
b8df4a36 197
ea272257
MCC
198Extended error information
199--------------------------
f404da6e
TZ
200
201 For some error conditions encountered when invoking a hist trigger
202 command, extended error information is available via the
26a94491
TZ
203 tracing/error_log file. See Error Conditions in
204 :file:`Documentation/trace/ftrace.rst` for details.
f404da6e 205
b8df4a36
TZ
2066.2 'hist' trigger examples
207---------------------------
208
209 The first set of examples creates aggregations using the kmalloc
210 event. The fields that can be used for the hist trigger are listed
ea272257 211 in the kmalloc event's format file::
b8df4a36
TZ
212
213 # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/format
214 name: kmalloc
215 ID: 374
216 format:
217 field:unsigned short common_type; offset:0; size:2; signed:0;
218 field:unsigned char common_flags; offset:2; size:1; signed:0;
219 field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
220 field:int common_pid; offset:4; size:4; signed:1;
221
222 field:unsigned long call_site; offset:8; size:8; signed:0;
223 field:const void * ptr; offset:16; size:8; signed:0;
224 field:size_t bytes_req; offset:24; size:8; signed:0;
225 field:size_t bytes_alloc; offset:32; size:8; signed:0;
226 field:gfp_t gfp_flags; offset:40; size:4; signed:0;
227
228 We'll start by creating a hist trigger that generates a simple table
229 that lists the total number of bytes requested for each function in
ea272257 230 the kernel that made one or more calls to kmalloc::
b8df4a36 231
37036435 232 # echo 'hist:key=call_site:val=bytes_req.buckets=32' > \
b8df4a36
TZ
233 /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
234
235 This tells the tracing system to create a 'hist' trigger using the
236 call_site field of the kmalloc event as the key for the table, which
237 just means that each unique call_site address will have an entry
238 created for it in the table. The 'val=bytes_req' parameter tells
239 the hist trigger that for each unique entry (call_site) in the
240 table, it should keep a running total of the number of bytes
241 requested by that call_site.
242
243 We'll let it run for awhile and then dump the contents of the 'hist'
244 file in the kmalloc event's subdirectory (for readability, a number
ea272257 245 of entries have been omitted)::
b8df4a36
TZ
246
247 # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
248 # trigger info: hist:keys=call_site:vals=bytes_req:sort=hitcount:size=2048 [active]
249
250 { call_site: 18446744072106379007 } hitcount: 1 bytes_req: 176
251 { call_site: 18446744071579557049 } hitcount: 1 bytes_req: 1024
252 { call_site: 18446744071580608289 } hitcount: 1 bytes_req: 16384
253 { call_site: 18446744071581827654 } hitcount: 1 bytes_req: 24
254 { call_site: 18446744071580700980 } hitcount: 1 bytes_req: 8
255 { call_site: 18446744071579359876 } hitcount: 1 bytes_req: 152
256 { call_site: 18446744071580795365 } hitcount: 3 bytes_req: 144
257 { call_site: 18446744071581303129 } hitcount: 3 bytes_req: 144
258 { call_site: 18446744071580713234 } hitcount: 4 bytes_req: 2560
259 { call_site: 18446744071580933750 } hitcount: 4 bytes_req: 736
260 .
261 .
262 .
263 { call_site: 18446744072106047046 } hitcount: 69 bytes_req: 5576
264 { call_site: 18446744071582116407 } hitcount: 73 bytes_req: 2336
265 { call_site: 18446744072106054684 } hitcount: 136 bytes_req: 140504
266 { call_site: 18446744072106224230 } hitcount: 136 bytes_req: 19584
267 { call_site: 18446744072106078074 } hitcount: 153 bytes_req: 2448
268 { call_site: 18446744072106062406 } hitcount: 153 bytes_req: 36720
269 { call_site: 18446744071582507929 } hitcount: 153 bytes_req: 37088
270 { call_site: 18446744072102520590 } hitcount: 273 bytes_req: 10920
271 { call_site: 18446744071582143559 } hitcount: 358 bytes_req: 716
272 { call_site: 18446744072106465852 } hitcount: 417 bytes_req: 56712
273 { call_site: 18446744072102523378 } hitcount: 485 bytes_req: 27160
274 { call_site: 18446744072099568646 } hitcount: 1676 bytes_req: 33520
275
276 Totals:
277 Hits: 4610
278 Entries: 45
279 Dropped: 0
280
281 The output displays a line for each entry, beginning with the key
282 specified in the trigger, followed by the value(s) also specified in
283 the trigger. At the beginning of the output is a line that displays
284 the trigger info, which can also be displayed by reading the
ea272257 285 'trigger' file::
b8df4a36
TZ
286
287 # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
288 hist:keys=call_site:vals=bytes_req:sort=hitcount:size=2048 [active]
289
290 At the end of the output are a few lines that display the overall
291 totals for the run. The 'Hits' field shows the total number of
292 times the event trigger was hit, the 'Entries' field shows the total
293 number of used entries in the hash table, and the 'Dropped' field
294 shows the number of hits that were dropped because the number of
295 used entries for the run exceeded the maximum number of entries
296 allowed for the table (normally 0, but if not a hint that you may
297 want to increase the size of the table using the 'size' parameter).
298
299 Notice in the above output that there's an extra field, 'hitcount',
300 which wasn't specified in the trigger. Also notice that in the
301 trigger info output, there's a parameter, 'sort=hitcount', which
302 wasn't specified in the trigger either. The reason for that is that
303 every trigger implicitly keeps a count of the total number of hits
304 attributed to a given entry, called the 'hitcount'. That hitcount
305 information is explicitly displayed in the output, and in the
306 absence of a user-specified sort parameter, is used as the default
307 sort field.
308
309 The value 'hitcount' can be used in place of an explicit value in
310 the 'values' parameter if you don't really need to have any
311 particular field summed and are mainly interested in hit
312 frequencies.
313
314 To turn the hist trigger off, simply call up the trigger in the
ea272257 315 command history and re-execute it with a '!' prepended::
b8df4a36
TZ
316
317 # echo '!hist:key=call_site:val=bytes_req' > \
318 /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
319
320 Finally, notice that the call_site as displayed in the output above
321 isn't really very useful. It's an address, but normally addresses
322 are displayed in hex. To have a numeric field displayed as a hex
ea272257 323 value, simply append '.hex' to the field name in the trigger::
b8df4a36
TZ
324
325 # echo 'hist:key=call_site.hex:val=bytes_req' > \
326 /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
327
328 # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
329 # trigger info: hist:keys=call_site.hex:vals=bytes_req:sort=hitcount:size=2048 [active]
330
331 { call_site: ffffffffa026b291 } hitcount: 1 bytes_req: 433
332 { call_site: ffffffffa07186ff } hitcount: 1 bytes_req: 176
333 { call_site: ffffffff811ae721 } hitcount: 1 bytes_req: 16384
334 { call_site: ffffffff811c5134 } hitcount: 1 bytes_req: 8
335 { call_site: ffffffffa04a9ebb } hitcount: 1 bytes_req: 511
336 { call_site: ffffffff8122e0a6 } hitcount: 1 bytes_req: 12
337 { call_site: ffffffff8107da84 } hitcount: 1 bytes_req: 152
338 { call_site: ffffffff812d8246 } hitcount: 1 bytes_req: 24
339 { call_site: ffffffff811dc1e5 } hitcount: 3 bytes_req: 144
340 { call_site: ffffffffa02515e8 } hitcount: 3 bytes_req: 648
341 { call_site: ffffffff81258159 } hitcount: 3 bytes_req: 144
342 { call_site: ffffffff811c80f4 } hitcount: 4 bytes_req: 544
343 .
344 .
345 .
346 { call_site: ffffffffa06c7646 } hitcount: 106 bytes_req: 8024
347 { call_site: ffffffffa06cb246 } hitcount: 132 bytes_req: 31680
348 { call_site: ffffffffa06cef7a } hitcount: 132 bytes_req: 2112
349 { call_site: ffffffff8137e399 } hitcount: 132 bytes_req: 23232
350 { call_site: ffffffffa06c941c } hitcount: 185 bytes_req: 171360
351 { call_site: ffffffffa06f2a66 } hitcount: 185 bytes_req: 26640
352 { call_site: ffffffffa036a70e } hitcount: 265 bytes_req: 10600
353 { call_site: ffffffff81325447 } hitcount: 292 bytes_req: 584
354 { call_site: ffffffffa072da3c } hitcount: 446 bytes_req: 60656
355 { call_site: ffffffffa036b1f2 } hitcount: 526 bytes_req: 29456
356 { call_site: ffffffffa0099c06 } hitcount: 1780 bytes_req: 35600
357
358 Totals:
359 Hits: 4775
360 Entries: 46
361 Dropped: 0
362
363 Even that's only marginally more useful - while hex values do look
364 more like addresses, what users are typically more interested in
365 when looking at text addresses are the corresponding symbols
366 instead. To have an address displayed as symbolic value instead,
367 simply append '.sym' or '.sym-offset' to the field name in the
ea272257 368 trigger::
b8df4a36
TZ
369
370 # echo 'hist:key=call_site.sym:val=bytes_req' > \
371 /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
372
373 # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
374 # trigger info: hist:keys=call_site.sym:vals=bytes_req:sort=hitcount:size=2048 [active]
375
376 { call_site: [ffffffff810adcb9] syslog_print_all } hitcount: 1 bytes_req: 1024
377 { call_site: [ffffffff8154bc62] usb_control_msg } hitcount: 1 bytes_req: 8
378 { call_site: [ffffffffa00bf6fe] hidraw_send_report [hid] } hitcount: 1 bytes_req: 7
379 { call_site: [ffffffff8154acbe] usb_alloc_urb } hitcount: 1 bytes_req: 192
380 { call_site: [ffffffffa00bf1ca] hidraw_report_event [hid] } hitcount: 1 bytes_req: 7
381 { call_site: [ffffffff811e3a25] __seq_open_private } hitcount: 1 bytes_req: 40
382 { call_site: [ffffffff8109524a] alloc_fair_sched_group } hitcount: 2 bytes_req: 128
383 { call_site: [ffffffff811febd5] fsnotify_alloc_group } hitcount: 2 bytes_req: 528
384 { call_site: [ffffffff81440f58] __tty_buffer_request_room } hitcount: 2 bytes_req: 2624
385 { call_site: [ffffffff81200ba6] inotify_new_group } hitcount: 2 bytes_req: 96
386 { call_site: [ffffffffa05e19af] ieee80211_start_tx_ba_session [mac80211] } hitcount: 2 bytes_req: 464
387 { call_site: [ffffffff81672406] tcp_get_metrics } hitcount: 2 bytes_req: 304
388 { call_site: [ffffffff81097ec2] alloc_rt_sched_group } hitcount: 2 bytes_req: 128
389 { call_site: [ffffffff81089b05] sched_create_group } hitcount: 2 bytes_req: 1424
390 .
391 .
392 .
393 { call_site: [ffffffffa04a580c] intel_crtc_page_flip [i915] } hitcount: 1185 bytes_req: 123240
394 { call_site: [ffffffffa0287592] drm_mode_page_flip_ioctl [drm] } hitcount: 1185 bytes_req: 104280
395 { call_site: [ffffffffa04c4a3c] intel_plane_duplicate_state [i915] } hitcount: 1402 bytes_req: 190672
396 { call_site: [ffffffff812891ca] ext4_find_extent } hitcount: 1518 bytes_req: 146208
397 { call_site: [ffffffffa029070e] drm_vma_node_allow [drm] } hitcount: 1746 bytes_req: 69840
398 { call_site: [ffffffffa045e7c4] i915_gem_do_execbuffer.isra.23 [i915] } hitcount: 2021 bytes_req: 792312
399 { call_site: [ffffffffa02911f2] drm_modeset_lock_crtc [drm] } hitcount: 2592 bytes_req: 145152
400 { call_site: [ffffffffa0489a66] intel_ring_begin [i915] } hitcount: 2629 bytes_req: 378576
401 { call_site: [ffffffffa046041c] i915_gem_execbuffer2 [i915] } hitcount: 2629 bytes_req: 3783248
402 { call_site: [ffffffff81325607] apparmor_file_alloc_security } hitcount: 5192 bytes_req: 10384
403 { call_site: [ffffffffa00b7c06] hid_report_raw_event [hid] } hitcount: 5529 bytes_req: 110584
404 { call_site: [ffffffff8131ebf7] aa_alloc_task_context } hitcount: 21943 bytes_req: 702176
405 { call_site: [ffffffff8125847d] ext4_htree_store_dirent } hitcount: 55759 bytes_req: 5074265
406
407 Totals:
408 Hits: 109928
409 Entries: 71
410 Dropped: 0
411
412 Because the default sort key above is 'hitcount', the above shows a
413 the list of call_sites by increasing hitcount, so that at the bottom
414 we see the functions that made the most kmalloc calls during the
415 run. If instead we we wanted to see the top kmalloc callers in
416 terms of the number of bytes requested rather than the number of
417 calls, and we wanted the top caller to appear at the top, we can use
ea272257 418 the 'sort' parameter, along with the 'descending' modifier::
b8df4a36
TZ
419
420 # echo 'hist:key=call_site.sym:val=bytes_req:sort=bytes_req.descending' > \
421 /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
422
423 # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
424 # trigger info: hist:keys=call_site.sym:vals=bytes_req:sort=bytes_req.descending:size=2048 [active]
425
426 { call_site: [ffffffffa046041c] i915_gem_execbuffer2 [i915] } hitcount: 2186 bytes_req: 3397464
427 { call_site: [ffffffffa045e7c4] i915_gem_do_execbuffer.isra.23 [i915] } hitcount: 1790 bytes_req: 712176
428 { call_site: [ffffffff8125847d] ext4_htree_store_dirent } hitcount: 8132 bytes_req: 513135
429 { call_site: [ffffffff811e2a1b] seq_buf_alloc } hitcount: 106 bytes_req: 440128
430 { call_site: [ffffffffa0489a66] intel_ring_begin [i915] } hitcount: 2186 bytes_req: 314784
431 { call_site: [ffffffff812891ca] ext4_find_extent } hitcount: 2174 bytes_req: 208992
432 { call_site: [ffffffff811ae8e1] __kmalloc } hitcount: 8 bytes_req: 131072
433 { call_site: [ffffffffa04c4a3c] intel_plane_duplicate_state [i915] } hitcount: 859 bytes_req: 116824
434 { call_site: [ffffffffa02911f2] drm_modeset_lock_crtc [drm] } hitcount: 1834 bytes_req: 102704
435 { call_site: [ffffffffa04a580c] intel_crtc_page_flip [i915] } hitcount: 972 bytes_req: 101088
436 { call_site: [ffffffffa0287592] drm_mode_page_flip_ioctl [drm] } hitcount: 972 bytes_req: 85536
437 { call_site: [ffffffffa00b7c06] hid_report_raw_event [hid] } hitcount: 3333 bytes_req: 66664
438 { call_site: [ffffffff8137e559] sg_kmalloc } hitcount: 209 bytes_req: 61632
439 .
440 .
441 .
442 { call_site: [ffffffff81095225] alloc_fair_sched_group } hitcount: 2 bytes_req: 128
443 { call_site: [ffffffff81097ec2] alloc_rt_sched_group } hitcount: 2 bytes_req: 128
444 { call_site: [ffffffff812d8406] copy_semundo } hitcount: 2 bytes_req: 48
445 { call_site: [ffffffff81200ba6] inotify_new_group } hitcount: 1 bytes_req: 48
446 { call_site: [ffffffffa027121a] drm_getmagic [drm] } hitcount: 1 bytes_req: 48
447 { call_site: [ffffffff811e3a25] __seq_open_private } hitcount: 1 bytes_req: 40
448 { call_site: [ffffffff811c52f4] bprm_change_interp } hitcount: 2 bytes_req: 16
449 { call_site: [ffffffff8154bc62] usb_control_msg } hitcount: 1 bytes_req: 8
450 { call_site: [ffffffffa00bf1ca] hidraw_report_event [hid] } hitcount: 1 bytes_req: 7
451 { call_site: [ffffffffa00bf6fe] hidraw_send_report [hid] } hitcount: 1 bytes_req: 7
452
453 Totals:
454 Hits: 32133
455 Entries: 81
456 Dropped: 0
457
458 To display the offset and size information in addition to the symbol
ea272257 459 name, just use 'sym-offset' instead::
b8df4a36
TZ
460
461 # echo 'hist:key=call_site.sym-offset:val=bytes_req:sort=bytes_req.descending' > \
462 /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
463
464 # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
465 # trigger info: hist:keys=call_site.sym-offset:vals=bytes_req:sort=bytes_req.descending:size=2048 [active]
466
467 { call_site: [ffffffffa046041c] i915_gem_execbuffer2+0x6c/0x2c0 [i915] } hitcount: 4569 bytes_req: 3163720
468 { call_site: [ffffffffa0489a66] intel_ring_begin+0xc6/0x1f0 [i915] } hitcount: 4569 bytes_req: 657936
469 { call_site: [ffffffffa045e7c4] i915_gem_do_execbuffer.isra.23+0x694/0x1020 [i915] } hitcount: 1519 bytes_req: 472936
470 { call_site: [ffffffffa045e646] i915_gem_do_execbuffer.isra.23+0x516/0x1020 [i915] } hitcount: 3050 bytes_req: 211832
471 { call_site: [ffffffff811e2a1b] seq_buf_alloc+0x1b/0x50 } hitcount: 34 bytes_req: 148384
472 { call_site: [ffffffffa04a580c] intel_crtc_page_flip+0xbc/0x870 [i915] } hitcount: 1385 bytes_req: 144040
473 { call_site: [ffffffff811ae8e1] __kmalloc+0x191/0x1b0 } hitcount: 8 bytes_req: 131072
474 { call_site: [ffffffffa0287592] drm_mode_page_flip_ioctl+0x282/0x360 [drm] } hitcount: 1385 bytes_req: 121880
475 { call_site: [ffffffffa02911f2] drm_modeset_lock_crtc+0x32/0x100 [drm] } hitcount: 1848 bytes_req: 103488
476 { call_site: [ffffffffa04c4a3c] intel_plane_duplicate_state+0x2c/0xa0 [i915] } hitcount: 461 bytes_req: 62696
477 { call_site: [ffffffffa029070e] drm_vma_node_allow+0x2e/0xd0 [drm] } hitcount: 1541 bytes_req: 61640
478 { call_site: [ffffffff815f8d7b] sk_prot_alloc+0xcb/0x1b0 } hitcount: 57 bytes_req: 57456
479 .
480 .
481 .
482 { call_site: [ffffffff8109524a] alloc_fair_sched_group+0x5a/0x1a0 } hitcount: 2 bytes_req: 128
483 { call_site: [ffffffffa027b921] drm_vm_open_locked+0x31/0xa0 [drm] } hitcount: 3 bytes_req: 96
484 { call_site: [ffffffff8122e266] proc_self_follow_link+0x76/0xb0 } hitcount: 8 bytes_req: 96
485 { call_site: [ffffffff81213e80] load_elf_binary+0x240/0x1650 } hitcount: 3 bytes_req: 84
486 { call_site: [ffffffff8154bc62] usb_control_msg+0x42/0x110 } hitcount: 1 bytes_req: 8
487 { call_site: [ffffffffa00bf6fe] hidraw_send_report+0x7e/0x1a0 [hid] } hitcount: 1 bytes_req: 7
488 { call_site: [ffffffffa00bf1ca] hidraw_report_event+0x8a/0x120 [hid] } hitcount: 1 bytes_req: 7
489
490 Totals:
491 Hits: 26098
492 Entries: 64
493 Dropped: 0
494
495 We can also add multiple fields to the 'values' parameter. For
496 example, we might want to see the total number of bytes allocated
497 alongside bytes requested, and display the result sorted by bytes
ea272257 498 allocated in a descending order::
b8df4a36
TZ
499
500 # echo 'hist:keys=call_site.sym:values=bytes_req,bytes_alloc:sort=bytes_alloc.descending' > \
501 /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
502
503 # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
504 # trigger info: hist:keys=call_site.sym:vals=bytes_req,bytes_alloc:sort=bytes_alloc.descending:size=2048 [active]
505
506 { call_site: [ffffffffa046041c] i915_gem_execbuffer2 [i915] } hitcount: 7403 bytes_req: 4084360 bytes_alloc: 5958016
507 { call_site: [ffffffff811e2a1b] seq_buf_alloc } hitcount: 541 bytes_req: 2213968 bytes_alloc: 2228224
508 { call_site: [ffffffffa0489a66] intel_ring_begin [i915] } hitcount: 7404 bytes_req: 1066176 bytes_alloc: 1421568
509 { call_site: [ffffffffa045e7c4] i915_gem_do_execbuffer.isra.23 [i915] } hitcount: 1565 bytes_req: 557368 bytes_alloc: 1037760
510 { call_site: [ffffffff8125847d] ext4_htree_store_dirent } hitcount: 9557 bytes_req: 595778 bytes_alloc: 695744
511 { call_site: [ffffffffa045e646] i915_gem_do_execbuffer.isra.23 [i915] } hitcount: 5839 bytes_req: 430680 bytes_alloc: 470400
512 { call_site: [ffffffffa04c4a3c] intel_plane_duplicate_state [i915] } hitcount: 2388 bytes_req: 324768 bytes_alloc: 458496
513 { call_site: [ffffffffa02911f2] drm_modeset_lock_crtc [drm] } hitcount: 3911 bytes_req: 219016 bytes_alloc: 250304
514 { call_site: [ffffffff815f8d7b] sk_prot_alloc } hitcount: 235 bytes_req: 236880 bytes_alloc: 240640
515 { call_site: [ffffffff8137e559] sg_kmalloc } hitcount: 557 bytes_req: 169024 bytes_alloc: 221760
516 { call_site: [ffffffffa00b7c06] hid_report_raw_event [hid] } hitcount: 9378 bytes_req: 187548 bytes_alloc: 206312
517 { call_site: [ffffffffa04a580c] intel_crtc_page_flip [i915] } hitcount: 1519 bytes_req: 157976 bytes_alloc: 194432
518 .
519 .
520 .
521 { call_site: [ffffffff8109bd3b] sched_autogroup_create_attach } hitcount: 2 bytes_req: 144 bytes_alloc: 192
522 { call_site: [ffffffff81097ee8] alloc_rt_sched_group } hitcount: 2 bytes_req: 128 bytes_alloc: 128
523 { call_site: [ffffffff8109524a] alloc_fair_sched_group } hitcount: 2 bytes_req: 128 bytes_alloc: 128
524 { call_site: [ffffffff81095225] alloc_fair_sched_group } hitcount: 2 bytes_req: 128 bytes_alloc: 128
525 { call_site: [ffffffff81097ec2] alloc_rt_sched_group } hitcount: 2 bytes_req: 128 bytes_alloc: 128
526 { call_site: [ffffffff81213e80] load_elf_binary } hitcount: 3 bytes_req: 84 bytes_alloc: 96
527 { call_site: [ffffffff81079a2e] kthread_create_on_node } hitcount: 1 bytes_req: 56 bytes_alloc: 64
528 { call_site: [ffffffffa00bf6fe] hidraw_send_report [hid] } hitcount: 1 bytes_req: 7 bytes_alloc: 8
529 { call_site: [ffffffff8154bc62] usb_control_msg } hitcount: 1 bytes_req: 8 bytes_alloc: 8
530 { call_site: [ffffffffa00bf1ca] hidraw_report_event [hid] } hitcount: 1 bytes_req: 7 bytes_alloc: 8
531
532 Totals:
533 Hits: 66598
534 Entries: 65
535 Dropped: 0
536
537 Finally, to finish off our kmalloc example, instead of simply having
538 the hist trigger display symbolic call_sites, we can have the hist
539 trigger additionally display the complete set of kernel stack traces
540 that led to each call_site. To do that, we simply use the special
ea272257 541 value 'stacktrace' for the key parameter::
b8df4a36
TZ
542
543 # echo 'hist:keys=stacktrace:values=bytes_req,bytes_alloc:sort=bytes_alloc' > \
544 /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
545
546 The above trigger will use the kernel stack trace in effect when an
547 event is triggered as the key for the hash table. This allows the
548 enumeration of every kernel callpath that led up to a particular
549 event, along with a running total of any of the event fields for
550 that event. Here we tally bytes requested and bytes allocated for
551 every callpath in the system that led up to a kmalloc (in this case
ea272257 552 every callpath to a kmalloc for a kernel compile)::
b8df4a36
TZ
553
554 # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
555 # trigger info: hist:keys=stacktrace:vals=bytes_req,bytes_alloc:sort=bytes_alloc:size=2048 [active]
556
557 { stacktrace:
558 __kmalloc_track_caller+0x10b/0x1a0
559 kmemdup+0x20/0x50
560 hidraw_report_event+0x8a/0x120 [hid]
561 hid_report_raw_event+0x3ea/0x440 [hid]
562 hid_input_report+0x112/0x190 [hid]
563 hid_irq_in+0xc2/0x260 [usbhid]
564 __usb_hcd_giveback_urb+0x72/0x120
565 usb_giveback_urb_bh+0x9e/0xe0
566 tasklet_hi_action+0xf8/0x100
567 __do_softirq+0x114/0x2c0
568 irq_exit+0xa5/0xb0
569 do_IRQ+0x5a/0xf0
570 ret_from_intr+0x0/0x30
571 cpuidle_enter+0x17/0x20
572 cpu_startup_entry+0x315/0x3e0
573 rest_init+0x7c/0x80
574 } hitcount: 3 bytes_req: 21 bytes_alloc: 24
575 { stacktrace:
576 __kmalloc_track_caller+0x10b/0x1a0
577 kmemdup+0x20/0x50
578 hidraw_report_event+0x8a/0x120 [hid]
579 hid_report_raw_event+0x3ea/0x440 [hid]
580 hid_input_report+0x112/0x190 [hid]
581 hid_irq_in+0xc2/0x260 [usbhid]
582 __usb_hcd_giveback_urb+0x72/0x120
583 usb_giveback_urb_bh+0x9e/0xe0
584 tasklet_hi_action+0xf8/0x100
585 __do_softirq+0x114/0x2c0
586 irq_exit+0xa5/0xb0
587 do_IRQ+0x5a/0xf0
588 ret_from_intr+0x0/0x30
589 } hitcount: 3 bytes_req: 21 bytes_alloc: 24
590 { stacktrace:
591 kmem_cache_alloc_trace+0xeb/0x150
592 aa_alloc_task_context+0x27/0x40
593 apparmor_cred_prepare+0x1f/0x50
594 security_prepare_creds+0x16/0x20
595 prepare_creds+0xdf/0x1a0
596 SyS_capset+0xb5/0x200
597 system_call_fastpath+0x12/0x6a
598 } hitcount: 1 bytes_req: 32 bytes_alloc: 32
599 .
600 .
601 .
602 { stacktrace:
603 __kmalloc+0x11b/0x1b0
604 i915_gem_execbuffer2+0x6c/0x2c0 [i915]
605 drm_ioctl+0x349/0x670 [drm]
606 do_vfs_ioctl+0x2f0/0x4f0
607 SyS_ioctl+0x81/0xa0
608 system_call_fastpath+0x12/0x6a
609 } hitcount: 17726 bytes_req: 13944120 bytes_alloc: 19593808
610 { stacktrace:
611 __kmalloc+0x11b/0x1b0
612 load_elf_phdrs+0x76/0xa0
613 load_elf_binary+0x102/0x1650
614 search_binary_handler+0x97/0x1d0
615 do_execveat_common.isra.34+0x551/0x6e0
616 SyS_execve+0x3a/0x50
617 return_from_execve+0x0/0x23
618 } hitcount: 33348 bytes_req: 17152128 bytes_alloc: 20226048
619 { stacktrace:
620 kmem_cache_alloc_trace+0xeb/0x150
621 apparmor_file_alloc_security+0x27/0x40
622 security_file_alloc+0x16/0x20
623 get_empty_filp+0x93/0x1c0
624 path_openat+0x31/0x5f0
625 do_filp_open+0x3a/0x90
626 do_sys_open+0x128/0x220
627 SyS_open+0x1e/0x20
628 system_call_fastpath+0x12/0x6a
629 } hitcount: 4766422 bytes_req: 9532844 bytes_alloc: 38131376
630 { stacktrace:
631 __kmalloc+0x11b/0x1b0
632 seq_buf_alloc+0x1b/0x50
633 seq_read+0x2cc/0x370
634 proc_reg_read+0x3d/0x80
635 __vfs_read+0x28/0xe0
636 vfs_read+0x86/0x140
637 SyS_read+0x46/0xb0
638 system_call_fastpath+0x12/0x6a
639 } hitcount: 19133 bytes_req: 78368768 bytes_alloc: 78368768
640
641 Totals:
642 Hits: 6085872
643 Entries: 253
644 Dropped: 0
645
646 If you key a hist trigger on common_pid, in order for example to
647 gather and display sorted totals for each process, you can use the
648 special .execname modifier to display the executable names for the
649 processes in the table rather than raw pids. The example below
ea272257 650 keeps a per-process sum of total bytes read::
b8df4a36
TZ
651
652 # echo 'hist:key=common_pid.execname:val=count:sort=count.descending' > \
653 /sys/kernel/debug/tracing/events/syscalls/sys_enter_read/trigger
654
655 # cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_read/hist
656 # trigger info: hist:keys=common_pid.execname:vals=count:sort=count.descending:size=2048 [active]
657
658 { common_pid: gnome-terminal [ 3196] } hitcount: 280 count: 1093512
659 { common_pid: Xorg [ 1309] } hitcount: 525 count: 256640
660 { common_pid: compiz [ 2889] } hitcount: 59 count: 254400
661 { common_pid: bash [ 8710] } hitcount: 3 count: 66369
662 { common_pid: dbus-daemon-lau [ 8703] } hitcount: 49 count: 47739
663 { common_pid: irqbalance [ 1252] } hitcount: 27 count: 27648
664 { common_pid: 01ifupdown [ 8705] } hitcount: 3 count: 17216
665 { common_pid: dbus-daemon [ 772] } hitcount: 10 count: 12396
666 { common_pid: Socket Thread [ 8342] } hitcount: 11 count: 11264
667 { common_pid: nm-dhcp-client. [ 8701] } hitcount: 6 count: 7424
668 { common_pid: gmain [ 1315] } hitcount: 18 count: 6336
669 .
670 .
671 .
672 { common_pid: postgres [ 1892] } hitcount: 2 count: 32
673 { common_pid: postgres [ 1891] } hitcount: 2 count: 32
674 { common_pid: gmain [ 8704] } hitcount: 2 count: 32
675 { common_pid: upstart-dbus-br [ 2740] } hitcount: 21 count: 21
676 { common_pid: nm-dispatcher.a [ 8696] } hitcount: 1 count: 16
677 { common_pid: indicator-datet [ 2904] } hitcount: 1 count: 16
678 { common_pid: gdbus [ 2998] } hitcount: 1 count: 16
679 { common_pid: rtkit-daemon [ 2052] } hitcount: 1 count: 8
680 { common_pid: init [ 1] } hitcount: 2 count: 2
681
682 Totals:
683 Hits: 2116
684 Entries: 51
685 Dropped: 0
686
687 Similarly, if you key a hist trigger on syscall id, for example to
688 gather and display a list of systemwide syscall hits, you can use
689 the special .syscall modifier to display the syscall names rather
690 than raw ids. The example below keeps a running total of syscall
ea272257 691 counts for the system during the run::
b8df4a36
TZ
692
693 # echo 'hist:key=id.syscall:val=hitcount' > \
694 /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/trigger
695
696 # cat /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/hist
697 # trigger info: hist:keys=id.syscall:vals=hitcount:sort=hitcount:size=2048 [active]
698
699 { id: sys_fsync [ 74] } hitcount: 1
700 { id: sys_newuname [ 63] } hitcount: 1
701 { id: sys_prctl [157] } hitcount: 1
702 { id: sys_statfs [137] } hitcount: 1
703 { id: sys_symlink [ 88] } hitcount: 1
704 { id: sys_sendmmsg [307] } hitcount: 1
705 { id: sys_semctl [ 66] } hitcount: 1
706 { id: sys_readlink [ 89] } hitcount: 3
707 { id: sys_bind [ 49] } hitcount: 3
708 { id: sys_getsockname [ 51] } hitcount: 3
709 { id: sys_unlink [ 87] } hitcount: 3
710 { id: sys_rename [ 82] } hitcount: 4
711 { id: unknown_syscall [ 58] } hitcount: 4
712 { id: sys_connect [ 42] } hitcount: 4
713 { id: sys_getpid [ 39] } hitcount: 4
714 .
715 .
716 .
717 { id: sys_rt_sigprocmask [ 14] } hitcount: 952
718 { id: sys_futex [202] } hitcount: 1534
719 { id: sys_write [ 1] } hitcount: 2689
720 { id: sys_setitimer [ 38] } hitcount: 2797
721 { id: sys_read [ 0] } hitcount: 3202
722 { id: sys_select [ 23] } hitcount: 3773
723 { id: sys_writev [ 20] } hitcount: 4531
724 { id: sys_poll [ 7] } hitcount: 8314
725 { id: sys_recvmsg [ 47] } hitcount: 13738
726 { id: sys_ioctl [ 16] } hitcount: 21843
727
728 Totals:
729 Hits: 67612
730 Entries: 72
731 Dropped: 0
732
ea272257
MCC
733 The syscall counts above provide a rough overall picture of system
734 call activity on the system; we can see for example that the most
735 popular system call on this system was the 'sys_ioctl' system call.
b8df4a36 736
ea272257
MCC
737 We can use 'compound' keys to refine that number and provide some
738 further insight as to which processes exactly contribute to the
739 overall ioctl count.
b8df4a36 740
ea272257
MCC
741 The command below keeps a hitcount for every unique combination of
742 system call id and pid - the end result is essentially a table
743 that keeps a per-pid sum of system call hits. The results are
744 sorted using the system call id as the primary key, and the
745 hitcount sum as the secondary key::
b8df4a36
TZ
746
747 # echo 'hist:key=id.syscall,common_pid.execname:val=hitcount:sort=id,hitcount' > \
748 /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/trigger
749
750 # cat /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/hist
751 # trigger info: hist:keys=id.syscall,common_pid.execname:vals=hitcount:sort=id.syscall,hitcount:size=2048 [active]
752
753 { id: sys_read [ 0], common_pid: rtkit-daemon [ 1877] } hitcount: 1
754 { id: sys_read [ 0], common_pid: gdbus [ 2976] } hitcount: 1
755 { id: sys_read [ 0], common_pid: console-kit-dae [ 3400] } hitcount: 1
756 { id: sys_read [ 0], common_pid: postgres [ 1865] } hitcount: 1
757 { id: sys_read [ 0], common_pid: deja-dup-monito [ 3543] } hitcount: 2
758 { id: sys_read [ 0], common_pid: NetworkManager [ 890] } hitcount: 2
759 { id: sys_read [ 0], common_pid: evolution-calen [ 3048] } hitcount: 2
760 { id: sys_read [ 0], common_pid: postgres [ 1864] } hitcount: 2
761 { id: sys_read [ 0], common_pid: nm-applet [ 3022] } hitcount: 2
762 { id: sys_read [ 0], common_pid: whoopsie [ 1212] } hitcount: 2
763 .
764 .
765 .
766 { id: sys_ioctl [ 16], common_pid: bash [ 8479] } hitcount: 1
767 { id: sys_ioctl [ 16], common_pid: bash [ 3472] } hitcount: 12
768 { id: sys_ioctl [ 16], common_pid: gnome-terminal [ 3199] } hitcount: 16
769 { id: sys_ioctl [ 16], common_pid: Xorg [ 1267] } hitcount: 1808
770 { id: sys_ioctl [ 16], common_pid: compiz [ 2994] } hitcount: 5580
771 .
772 .
773 .
774 { id: sys_waitid [247], common_pid: upstart-dbus-br [ 2690] } hitcount: 3
775 { id: sys_waitid [247], common_pid: upstart-dbus-br [ 2688] } hitcount: 16
776 { id: sys_inotify_add_watch [254], common_pid: gmain [ 975] } hitcount: 2
777 { id: sys_inotify_add_watch [254], common_pid: gmain [ 3204] } hitcount: 4
778 { id: sys_inotify_add_watch [254], common_pid: gmain [ 2888] } hitcount: 4
779 { id: sys_inotify_add_watch [254], common_pid: gmain [ 3003] } hitcount: 4
780 { id: sys_inotify_add_watch [254], common_pid: gmain [ 2873] } hitcount: 4
781 { id: sys_inotify_add_watch [254], common_pid: gmain [ 3196] } hitcount: 6
782 { id: sys_openat [257], common_pid: java [ 2623] } hitcount: 2
783 { id: sys_eventfd2 [290], common_pid: ibus-ui-gtk3 [ 2760] } hitcount: 4
784 { id: sys_eventfd2 [290], common_pid: compiz [ 2994] } hitcount: 6
785
786 Totals:
787 Hits: 31536
788 Entries: 323
789 Dropped: 0
790
ea272257
MCC
791 The above list does give us a breakdown of the ioctl syscall by
792 pid, but it also gives us quite a bit more than that, which we
793 don't really care about at the moment. Since we know the syscall
794 id for sys_ioctl (16, displayed next to the sys_ioctl name), we
795 can use that to filter out all the other syscalls::
b8df4a36
TZ
796
797 # echo 'hist:key=id.syscall,common_pid.execname:val=hitcount:sort=id,hitcount if id == 16' > \
798 /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/trigger
799
800 # cat /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/hist
801 # trigger info: hist:keys=id.syscall,common_pid.execname:vals=hitcount:sort=id.syscall,hitcount:size=2048 if id == 16 [active]
802
803 { id: sys_ioctl [ 16], common_pid: gmain [ 2769] } hitcount: 1
804 { id: sys_ioctl [ 16], common_pid: evolution-addre [ 8571] } hitcount: 1
805 { id: sys_ioctl [ 16], common_pid: gmain [ 3003] } hitcount: 1
806 { id: sys_ioctl [ 16], common_pid: gmain [ 2781] } hitcount: 1
807 { id: sys_ioctl [ 16], common_pid: gmain [ 2829] } hitcount: 1
808 { id: sys_ioctl [ 16], common_pid: bash [ 8726] } hitcount: 1
809 { id: sys_ioctl [ 16], common_pid: bash [ 8508] } hitcount: 1
810 { id: sys_ioctl [ 16], common_pid: gmain [ 2970] } hitcount: 1
811 { id: sys_ioctl [ 16], common_pid: gmain [ 2768] } hitcount: 1
812 .
813 .
814 .
815 { id: sys_ioctl [ 16], common_pid: pool [ 8559] } hitcount: 45
816 { id: sys_ioctl [ 16], common_pid: pool [ 8555] } hitcount: 48
817 { id: sys_ioctl [ 16], common_pid: pool [ 8551] } hitcount: 48
818 { id: sys_ioctl [ 16], common_pid: avahi-daemon [ 896] } hitcount: 66
819 { id: sys_ioctl [ 16], common_pid: Xorg [ 1267] } hitcount: 26674
820 { id: sys_ioctl [ 16], common_pid: compiz [ 2994] } hitcount: 73443
821
822 Totals:
823 Hits: 101162
824 Entries: 103
825 Dropped: 0
826
ea272257
MCC
827 The above output shows that 'compiz' and 'Xorg' are far and away
828 the heaviest ioctl callers (which might lead to questions about
829 whether they really need to be making all those calls and to
830 possible avenues for further investigation.)
b8df4a36 831
ea272257
MCC
832 The compound key examples used a key and a sum value (hitcount) to
833 sort the output, but we can just as easily use two keys instead.
834 Here's an example where we use a compound key composed of the the
835 common_pid and size event fields. Sorting with pid as the primary
836 key and 'size' as the secondary key allows us to display an
837 ordered summary of the recvfrom sizes, with counts, received by
838 each process::
b8df4a36
TZ
839
840 # echo 'hist:key=common_pid.execname,size:val=hitcount:sort=common_pid,size' > \
841 /sys/kernel/debug/tracing/events/syscalls/sys_enter_recvfrom/trigger
842
843 # cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_recvfrom/hist
844 # trigger info: hist:keys=common_pid.execname,size:vals=hitcount:sort=common_pid.execname,size:size=2048 [active]
845
846 { common_pid: smbd [ 784], size: 4 } hitcount: 1
847 { common_pid: dnsmasq [ 1412], size: 4096 } hitcount: 672
848 { common_pid: postgres [ 1796], size: 1000 } hitcount: 6
849 { common_pid: postgres [ 1867], size: 1000 } hitcount: 10
850 { common_pid: bamfdaemon [ 2787], size: 28 } hitcount: 2
851 { common_pid: bamfdaemon [ 2787], size: 14360 } hitcount: 1
852 { common_pid: compiz [ 2994], size: 8 } hitcount: 1
853 { common_pid: compiz [ 2994], size: 20 } hitcount: 11
854 { common_pid: gnome-terminal [ 3199], size: 4 } hitcount: 2
855 { common_pid: firefox [ 8817], size: 4 } hitcount: 1
856 { common_pid: firefox [ 8817], size: 8 } hitcount: 5
857 { common_pid: firefox [ 8817], size: 588 } hitcount: 2
858 { common_pid: firefox [ 8817], size: 628 } hitcount: 1
859 { common_pid: firefox [ 8817], size: 6944 } hitcount: 1
860 { common_pid: firefox [ 8817], size: 408880 } hitcount: 2
861 { common_pid: firefox [ 8822], size: 8 } hitcount: 2
862 { common_pid: firefox [ 8822], size: 160 } hitcount: 2
863 { common_pid: firefox [ 8822], size: 320 } hitcount: 2
864 { common_pid: firefox [ 8822], size: 352 } hitcount: 1
865 .
866 .
867 .
868 { common_pid: pool [ 8923], size: 1960 } hitcount: 10
869 { common_pid: pool [ 8923], size: 2048 } hitcount: 10
870 { common_pid: pool [ 8924], size: 1960 } hitcount: 10
871 { common_pid: pool [ 8924], size: 2048 } hitcount: 10
872 { common_pid: pool [ 8928], size: 1964 } hitcount: 4
873 { common_pid: pool [ 8928], size: 1965 } hitcount: 2
874 { common_pid: pool [ 8928], size: 2048 } hitcount: 6
875 { common_pid: pool [ 8929], size: 1982 } hitcount: 1
876 { common_pid: pool [ 8929], size: 2048 } hitcount: 1
877
878 Totals:
879 Hits: 2016
880 Entries: 224
881 Dropped: 0
882
883 The above example also illustrates the fact that although a compound
884 key is treated as a single entity for hashing purposes, the sub-keys
885 it's composed of can be accessed independently.
886
887 The next example uses a string field as the hash key and
888 demonstrates how you can manually pause and continue a hist trigger.
889 In this example, we'll aggregate fork counts and don't expect a
890 large number of entries in the hash table, so we'll drop it to a
ea272257 891 much smaller number, say 256::
b8df4a36
TZ
892
893 # echo 'hist:key=child_comm:val=hitcount:size=256' > \
894 /sys/kernel/debug/tracing/events/sched/sched_process_fork/trigger
895
896 # cat /sys/kernel/debug/tracing/events/sched/sched_process_fork/hist
897 # trigger info: hist:keys=child_comm:vals=hitcount:sort=hitcount:size=256 [active]
898
899 { child_comm: dconf worker } hitcount: 1
900 { child_comm: ibus-daemon } hitcount: 1
901 { child_comm: whoopsie } hitcount: 1
902 { child_comm: smbd } hitcount: 1
903 { child_comm: gdbus } hitcount: 1
904 { child_comm: kthreadd } hitcount: 1
905 { child_comm: dconf worker } hitcount: 1
906 { child_comm: evolution-alarm } hitcount: 2
907 { child_comm: Socket Thread } hitcount: 2
908 { child_comm: postgres } hitcount: 2
909 { child_comm: bash } hitcount: 3
910 { child_comm: compiz } hitcount: 3
911 { child_comm: evolution-sourc } hitcount: 4
912 { child_comm: dhclient } hitcount: 4
913 { child_comm: pool } hitcount: 5
914 { child_comm: nm-dispatcher.a } hitcount: 8
915 { child_comm: firefox } hitcount: 8
916 { child_comm: dbus-daemon } hitcount: 8
917 { child_comm: glib-pacrunner } hitcount: 10
918 { child_comm: evolution } hitcount: 23
919
920 Totals:
921 Hits: 89
922 Entries: 20
923 Dropped: 0
924
925 If we want to pause the hist trigger, we can simply append :pause to
926 the command that started the trigger. Notice that the trigger info
ea272257 927 displays as [paused]::
b8df4a36
TZ
928
929 # echo 'hist:key=child_comm:val=hitcount:size=256:pause' >> \
930 /sys/kernel/debug/tracing/events/sched/sched_process_fork/trigger
931
932 # cat /sys/kernel/debug/tracing/events/sched/sched_process_fork/hist
933 # trigger info: hist:keys=child_comm:vals=hitcount:sort=hitcount:size=256 [paused]
934
935 { child_comm: dconf worker } hitcount: 1
936 { child_comm: kthreadd } hitcount: 1
937 { child_comm: dconf worker } hitcount: 1
938 { child_comm: gdbus } hitcount: 1
939 { child_comm: ibus-daemon } hitcount: 1
940 { child_comm: Socket Thread } hitcount: 2
941 { child_comm: evolution-alarm } hitcount: 2
942 { child_comm: smbd } hitcount: 2
943 { child_comm: bash } hitcount: 3
944 { child_comm: whoopsie } hitcount: 3
945 { child_comm: compiz } hitcount: 3
946 { child_comm: evolution-sourc } hitcount: 4
947 { child_comm: pool } hitcount: 5
948 { child_comm: postgres } hitcount: 6
949 { child_comm: firefox } hitcount: 8
950 { child_comm: dhclient } hitcount: 10
951 { child_comm: emacs } hitcount: 12
952 { child_comm: dbus-daemon } hitcount: 20
953 { child_comm: nm-dispatcher.a } hitcount: 20
954 { child_comm: evolution } hitcount: 35
955 { child_comm: glib-pacrunner } hitcount: 59
956
957 Totals:
958 Hits: 199
959 Entries: 21
960 Dropped: 0
961
962 To manually continue having the trigger aggregate events, append
963 :cont instead. Notice that the trigger info displays as [active]
ea272257 964 again, and the data has changed::
b8df4a36
TZ
965
966 # echo 'hist:key=child_comm:val=hitcount:size=256:cont' >> \
967 /sys/kernel/debug/tracing/events/sched/sched_process_fork/trigger
968
969 # cat /sys/kernel/debug/tracing/events/sched/sched_process_fork/hist
970 # trigger info: hist:keys=child_comm:vals=hitcount:sort=hitcount:size=256 [active]
971
972 { child_comm: dconf worker } hitcount: 1
973 { child_comm: dconf worker } hitcount: 1
974 { child_comm: kthreadd } hitcount: 1
975 { child_comm: gdbus } hitcount: 1
976 { child_comm: ibus-daemon } hitcount: 1
977 { child_comm: Socket Thread } hitcount: 2
978 { child_comm: evolution-alarm } hitcount: 2
979 { child_comm: smbd } hitcount: 2
980 { child_comm: whoopsie } hitcount: 3
981 { child_comm: compiz } hitcount: 3
982 { child_comm: evolution-sourc } hitcount: 4
983 { child_comm: bash } hitcount: 5
984 { child_comm: pool } hitcount: 5
985 { child_comm: postgres } hitcount: 6
986 { child_comm: firefox } hitcount: 8
987 { child_comm: dhclient } hitcount: 11
988 { child_comm: emacs } hitcount: 12
989 { child_comm: dbus-daemon } hitcount: 22
990 { child_comm: nm-dispatcher.a } hitcount: 22
991 { child_comm: evolution } hitcount: 35
992 { child_comm: glib-pacrunner } hitcount: 59
993
994 Totals:
995 Hits: 206
996 Entries: 21
997 Dropped: 0
998
999 The previous example showed how to start and stop a hist trigger by
1000 appending 'pause' and 'continue' to the hist trigger command. A
1001 hist trigger can also be started in a paused state by initially
1002 starting the trigger with ':pause' appended. This allows you to
1003 start the trigger only when you're ready to start collecting data
1004 and not before. For example, you could start the trigger in a
1005 paused state, then unpause it and do something you want to measure,
1006 then pause the trigger again when done.
1007
1008 Of course, doing this manually can be difficult and error-prone, but
1009 it is possible to automatically start and stop a hist trigger based
1010 on some condition, via the enable_hist and disable_hist triggers.
1011
1012 For example, suppose we wanted to take a look at the relative
1013 weights in terms of skb length for each callpath that leads to a
fe4ec72c 1014 netif_receive_skb event when downloading a decent-sized file using
b8df4a36
TZ
1015 wget.
1016
1017 First we set up an initially paused stacktrace trigger on the
ea272257 1018 netif_receive_skb event::
b8df4a36
TZ
1019
1020 # echo 'hist:key=stacktrace:vals=len:pause' > \
1021 /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
1022
1023 Next, we set up an 'enable_hist' trigger on the sched_process_exec
1024 event, with an 'if filename==/usr/bin/wget' filter. The effect of
1025 this new trigger is that it will 'unpause' the hist trigger we just
1026 set up on netif_receive_skb if and only if it sees a
1027 sched_process_exec event with a filename of '/usr/bin/wget'. When
1028 that happens, all netif_receive_skb events are aggregated into a
ea272257 1029 hash table keyed on stacktrace::
b8df4a36
TZ
1030
1031 # echo 'enable_hist:net:netif_receive_skb if filename==/usr/bin/wget' > \
1032 /sys/kernel/debug/tracing/events/sched/sched_process_exec/trigger
1033
1034 The aggregation continues until the netif_receive_skb is paused
1035 again, which is what the following disable_hist event does by
1036 creating a similar setup on the sched_process_exit event, using the
ea272257 1037 filter 'comm==wget'::
b8df4a36
TZ
1038
1039 # echo 'disable_hist:net:netif_receive_skb if comm==wget' > \
1040 /sys/kernel/debug/tracing/events/sched/sched_process_exit/trigger
1041
1042 Whenever a process exits and the comm field of the disable_hist
1043 trigger filter matches 'comm==wget', the netif_receive_skb hist
1044 trigger is disabled.
1045
1046 The overall effect is that netif_receive_skb events are aggregated
1047 into the hash table for only the duration of the wget. Executing a
1048 wget command and then listing the 'hist' file will display the
ea272257 1049 output generated by the wget command::
b8df4a36
TZ
1050
1051 $ wget https://www.kernel.org/pub/linux/kernel/v3.x/patch-3.19.xz
1052
1053 # cat /sys/kernel/debug/tracing/events/net/netif_receive_skb/hist
1054 # trigger info: hist:keys=stacktrace:vals=len:sort=hitcount:size=2048 [paused]
1055
1056 { stacktrace:
1057 __netif_receive_skb_core+0x46d/0x990
1058 __netif_receive_skb+0x18/0x60
1059 netif_receive_skb_internal+0x23/0x90
1060 napi_gro_receive+0xc8/0x100
1061 ieee80211_deliver_skb+0xd6/0x270 [mac80211]
1062 ieee80211_rx_handlers+0xccf/0x22f0 [mac80211]
1063 ieee80211_prepare_and_rx_handle+0x4e7/0xc40 [mac80211]
1064 ieee80211_rx+0x31d/0x900 [mac80211]
1065 iwlagn_rx_reply_rx+0x3db/0x6f0 [iwldvm]
1066 iwl_rx_dispatch+0x8e/0xf0 [iwldvm]
1067 iwl_pcie_irq_handler+0xe3c/0x12f0 [iwlwifi]
1068 irq_thread_fn+0x20/0x50
1069 irq_thread+0x11f/0x150
1070 kthread+0xd2/0xf0
1071 ret_from_fork+0x42/0x70
1072 } hitcount: 85 len: 28884
1073 { stacktrace:
1074 __netif_receive_skb_core+0x46d/0x990
1075 __netif_receive_skb+0x18/0x60
1076 netif_receive_skb_internal+0x23/0x90
1077 napi_gro_complete+0xa4/0xe0
1078 dev_gro_receive+0x23a/0x360
1079 napi_gro_receive+0x30/0x100
1080 ieee80211_deliver_skb+0xd6/0x270 [mac80211]
1081 ieee80211_rx_handlers+0xccf/0x22f0 [mac80211]
1082 ieee80211_prepare_and_rx_handle+0x4e7/0xc40 [mac80211]
1083 ieee80211_rx+0x31d/0x900 [mac80211]
1084 iwlagn_rx_reply_rx+0x3db/0x6f0 [iwldvm]
1085 iwl_rx_dispatch+0x8e/0xf0 [iwldvm]
1086 iwl_pcie_irq_handler+0xe3c/0x12f0 [iwlwifi]
1087 irq_thread_fn+0x20/0x50
1088 irq_thread+0x11f/0x150
1089 kthread+0xd2/0xf0
1090 } hitcount: 98 len: 664329
1091 { stacktrace:
1092 __netif_receive_skb_core+0x46d/0x990
1093 __netif_receive_skb+0x18/0x60
1094 process_backlog+0xa8/0x150
1095 net_rx_action+0x15d/0x340
1096 __do_softirq+0x114/0x2c0
1097 do_softirq_own_stack+0x1c/0x30
1098 do_softirq+0x65/0x70
1099 __local_bh_enable_ip+0xb5/0xc0
1100 ip_finish_output+0x1f4/0x840
1101 ip_output+0x6b/0xc0
1102 ip_local_out_sk+0x31/0x40
1103 ip_send_skb+0x1a/0x50
1104 udp_send_skb+0x173/0x2a0
1105 udp_sendmsg+0x2bf/0x9f0
1106 inet_sendmsg+0x64/0xa0
1107 sock_sendmsg+0x3d/0x50
1108 } hitcount: 115 len: 13030
1109 { stacktrace:
1110 __netif_receive_skb_core+0x46d/0x990
1111 __netif_receive_skb+0x18/0x60
1112 netif_receive_skb_internal+0x23/0x90
1113 napi_gro_complete+0xa4/0xe0
1114 napi_gro_flush+0x6d/0x90
1115 iwl_pcie_irq_handler+0x92a/0x12f0 [iwlwifi]
1116 irq_thread_fn+0x20/0x50
1117 irq_thread+0x11f/0x150
1118 kthread+0xd2/0xf0
1119 ret_from_fork+0x42/0x70
1120 } hitcount: 934 len: 5512212
1121
1122 Totals:
1123 Hits: 1232
1124 Entries: 4
1125 Dropped: 0
1126
1127 The above shows all the netif_receive_skb callpaths and their total
1128 lengths for the duration of the wget command.
1129
1130 The 'clear' hist trigger param can be used to clear the hash table.
1131 Suppose we wanted to try another run of the previous example but
1132 this time also wanted to see the complete list of events that went
1133 into the histogram. In order to avoid having to set everything up
ea272257 1134 again, we can just clear the histogram first::
b8df4a36
TZ
1135
1136 # echo 'hist:key=stacktrace:vals=len:clear' >> \
1137 /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
1138
1139 Just to verify that it is in fact cleared, here's what we now see in
ea272257 1140 the hist file::
b8df4a36
TZ
1141
1142 # cat /sys/kernel/debug/tracing/events/net/netif_receive_skb/hist
1143 # trigger info: hist:keys=stacktrace:vals=len:sort=hitcount:size=2048 [paused]
1144
1145 Totals:
1146 Hits: 0
1147 Entries: 0
1148 Dropped: 0
1149
1150 Since we want to see the detailed list of every netif_receive_skb
1151 event occurring during the new run, which are in fact the same
1152 events being aggregated into the hash table, we add some additional
1153 'enable_event' events to the triggering sched_process_exec and
ea272257 1154 sched_process_exit events as such::
b8df4a36
TZ
1155
1156 # echo 'enable_event:net:netif_receive_skb if filename==/usr/bin/wget' > \
1157 /sys/kernel/debug/tracing/events/sched/sched_process_exec/trigger
1158
1159 # echo 'disable_event:net:netif_receive_skb if comm==wget' > \
1160 /sys/kernel/debug/tracing/events/sched/sched_process_exit/trigger
1161
1162 If you read the trigger files for the sched_process_exec and
1163 sched_process_exit triggers, you should see two triggers for each:
1164 one enabling/disabling the hist aggregation and the other
ea272257 1165 enabling/disabling the logging of events::
b8df4a36
TZ
1166
1167 # cat /sys/kernel/debug/tracing/events/sched/sched_process_exec/trigger
1168 enable_event:net:netif_receive_skb:unlimited if filename==/usr/bin/wget
1169 enable_hist:net:netif_receive_skb:unlimited if filename==/usr/bin/wget
1170
1171 # cat /sys/kernel/debug/tracing/events/sched/sched_process_exit/trigger
1172 enable_event:net:netif_receive_skb:unlimited if comm==wget
1173 disable_hist:net:netif_receive_skb:unlimited if comm==wget
1174
1175 In other words, whenever either of the sched_process_exec or
1176 sched_process_exit events is hit and matches 'wget', it enables or
1177 disables both the histogram and the event log, and what you end up
1178 with is a hash table and set of events just covering the specified
ea272257 1179 duration. Run the wget command again::
b8df4a36
TZ
1180
1181 $ wget https://www.kernel.org/pub/linux/kernel/v3.x/patch-3.19.xz
1182
1183 Displaying the 'hist' file should show something similar to what you
1184 saw in the last run, but this time you should also see the
ea272257 1185 individual events in the trace file::
b8df4a36
TZ
1186
1187 # cat /sys/kernel/debug/tracing/trace
1188
1189 # tracer: nop
1190 #
1191 # entries-in-buffer/entries-written: 183/1426 #P:4
1192 #
1193 # _-----=> irqs-off
1194 # / _----=> need-resched
1195 # | / _---=> hardirq/softirq
1196 # || / _--=> preempt-depth
1197 # ||| / delay
1198 # TASK-PID CPU# |||| TIMESTAMP FUNCTION
1199 # | | | |||| | |
1200 wget-15108 [000] ..s1 31769.606929: netif_receive_skb: dev=lo skbaddr=ffff88009c353100 len=60
1201 wget-15108 [000] ..s1 31769.606999: netif_receive_skb: dev=lo skbaddr=ffff88009c353200 len=60
1202 dnsmasq-1382 [000] ..s1 31769.677652: netif_receive_skb: dev=lo skbaddr=ffff88009c352b00 len=130
1203 dnsmasq-1382 [000] ..s1 31769.685917: netif_receive_skb: dev=lo skbaddr=ffff88009c352200 len=138
1204 ##### CPU 2 buffer started ####
1205 irq/29-iwlwifi-559 [002] ..s. 31772.031529: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d433d00 len=2948
1206 irq/29-iwlwifi-559 [002] ..s. 31772.031572: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d432200 len=1500
1207 irq/29-iwlwifi-559 [002] ..s. 31772.032196: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d433100 len=2948
1208 irq/29-iwlwifi-559 [002] ..s. 31772.032761: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d433000 len=2948
1209 irq/29-iwlwifi-559 [002] ..s. 31772.033220: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d432e00 len=1500
1210 .
1211 .
1212 .
1213
1214 The following example demonstrates how multiple hist triggers can be
1215 attached to a given event. This capability can be useful for
1216 creating a set of different summaries derived from the same set of
1217 events, or for comparing the effects of different filters, among
ea272257 1218 other things::
b8df4a36
TZ
1219
1220 # echo 'hist:keys=skbaddr.hex:vals=len if len < 0' >> \
1221 /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
1222 # echo 'hist:keys=skbaddr.hex:vals=len if len > 4096' >> \
1223 /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
1224 # echo 'hist:keys=skbaddr.hex:vals=len if len == 256' >> \
1225 /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
1226 # echo 'hist:keys=skbaddr.hex:vals=len' >> \
1227 /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
1228 # echo 'hist:keys=len:vals=common_preempt_count' >> \
1229 /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
1230
1231 The above set of commands create four triggers differing only in
1232 their filters, along with a completely different though fairly
1233 nonsensical trigger. Note that in order to append multiple hist
1234 triggers to the same file, you should use the '>>' operator to
1235 append them ('>' will also add the new hist trigger, but will remove
1236 any existing hist triggers beforehand).
1237
1238 Displaying the contents of the 'hist' file for the event shows the
ea272257 1239 contents of all five histograms::
b8df4a36
TZ
1240
1241 # cat /sys/kernel/debug/tracing/events/net/netif_receive_skb/hist
1242
1243 # event histogram
1244 #
1245 # trigger info: hist:keys=len:vals=hitcount,common_preempt_count:sort=hitcount:size=2048 [active]
1246 #
1247
1248 { len: 176 } hitcount: 1 common_preempt_count: 0
1249 { len: 223 } hitcount: 1 common_preempt_count: 0
1250 { len: 4854 } hitcount: 1 common_preempt_count: 0
1251 { len: 395 } hitcount: 1 common_preempt_count: 0
1252 { len: 177 } hitcount: 1 common_preempt_count: 0
1253 { len: 446 } hitcount: 1 common_preempt_count: 0
1254 { len: 1601 } hitcount: 1 common_preempt_count: 0
1255 .
1256 .
1257 .
1258 { len: 1280 } hitcount: 66 common_preempt_count: 0
1259 { len: 116 } hitcount: 81 common_preempt_count: 40
1260 { len: 708 } hitcount: 112 common_preempt_count: 0
1261 { len: 46 } hitcount: 221 common_preempt_count: 0
1262 { len: 1264 } hitcount: 458 common_preempt_count: 0
1263
1264 Totals:
1265 Hits: 1428
1266 Entries: 147
1267 Dropped: 0
1268
1269
1270 # event histogram
1271 #
1272 # trigger info: hist:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 [active]
1273 #
1274
1275 { skbaddr: ffff8800baee5e00 } hitcount: 1 len: 130
1276 { skbaddr: ffff88005f3d5600 } hitcount: 1 len: 1280
1277 { skbaddr: ffff88005f3d4900 } hitcount: 1 len: 1280
1278 { skbaddr: ffff88009fed6300 } hitcount: 1 len: 115
1279 { skbaddr: ffff88009fe0ad00 } hitcount: 1 len: 115
1280 { skbaddr: ffff88008cdb1900 } hitcount: 1 len: 46
1281 { skbaddr: ffff880064b5ef00 } hitcount: 1 len: 118
1282 { skbaddr: ffff880044e3c700 } hitcount: 1 len: 60
1283 { skbaddr: ffff880100065900 } hitcount: 1 len: 46
1284 { skbaddr: ffff8800d46bd500 } hitcount: 1 len: 116
1285 { skbaddr: ffff88005f3d5f00 } hitcount: 1 len: 1280
1286 { skbaddr: ffff880100064700 } hitcount: 1 len: 365
1287 { skbaddr: ffff8800badb6f00 } hitcount: 1 len: 60
1288 .
1289 .
1290 .
1291 { skbaddr: ffff88009fe0be00 } hitcount: 27 len: 24677
1292 { skbaddr: ffff88009fe0a400 } hitcount: 27 len: 23052
1293 { skbaddr: ffff88009fe0b700 } hitcount: 31 len: 25589
1294 { skbaddr: ffff88009fe0b600 } hitcount: 32 len: 27326
1295 { skbaddr: ffff88006a462800 } hitcount: 68 len: 71678
1296 { skbaddr: ffff88006a463700 } hitcount: 70 len: 72678
1297 { skbaddr: ffff88006a462b00 } hitcount: 71 len: 77589
1298 { skbaddr: ffff88006a463600 } hitcount: 73 len: 71307
1299 { skbaddr: ffff88006a462200 } hitcount: 81 len: 81032
1300
1301 Totals:
1302 Hits: 1451
1303 Entries: 318
1304 Dropped: 0
1305
1306
1307 # event histogram
1308 #
1309 # trigger info: hist:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 if len == 256 [active]
1310 #
1311
1312
1313 Totals:
1314 Hits: 0
1315 Entries: 0
1316 Dropped: 0
1317
1318
1319 # event histogram
1320 #
1321 # trigger info: hist:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 if len > 4096 [active]
1322 #
1323
1324 { skbaddr: ffff88009fd2c300 } hitcount: 1 len: 7212
1325 { skbaddr: ffff8800d2bcce00 } hitcount: 1 len: 7212
1326 { skbaddr: ffff8800d2bcd700 } hitcount: 1 len: 7212
1327 { skbaddr: ffff8800d2bcda00 } hitcount: 1 len: 21492
1328 { skbaddr: ffff8800ae2e2d00 } hitcount: 1 len: 7212
1329 { skbaddr: ffff8800d2bcdb00 } hitcount: 1 len: 7212
1330 { skbaddr: ffff88006a4df500 } hitcount: 1 len: 4854
1331 { skbaddr: ffff88008ce47b00 } hitcount: 1 len: 18636
1332 { skbaddr: ffff8800ae2e2200 } hitcount: 1 len: 12924
1333 { skbaddr: ffff88005f3e1000 } hitcount: 1 len: 4356
1334 { skbaddr: ffff8800d2bcdc00 } hitcount: 2 len: 24420
1335 { skbaddr: ffff8800d2bcc200 } hitcount: 2 len: 12996
1336
1337 Totals:
1338 Hits: 14
1339 Entries: 12
1340 Dropped: 0
1341
1342
1343 # event histogram
1344 #
1345 # trigger info: hist:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 if len < 0 [active]
1346 #
1347
1348
1349 Totals:
1350 Hits: 0
1351 Entries: 0
1352 Dropped: 0
1353
1354 Named triggers can be used to have triggers share a common set of
1355 histogram data. This capability is mostly useful for combining the
1356 output of events generated by tracepoints contained inside inline
1357 functions, but names can be used in a hist trigger on any event.
1358 For example, these two triggers when hit will update the same 'len'
ea272257 1359 field in the shared 'foo' histogram data::
b8df4a36
TZ
1360
1361 # echo 'hist:name=foo:keys=skbaddr.hex:vals=len' > \
1362 /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
1363 # echo 'hist:name=foo:keys=skbaddr.hex:vals=len' > \
1364 /sys/kernel/debug/tracing/events/net/netif_rx/trigger
1365
1366 You can see that they're updating common histogram data by reading
ea272257 1367 each event's hist files at the same time::
b8df4a36
TZ
1368
1369 # cat /sys/kernel/debug/tracing/events/net/netif_receive_skb/hist;
1370 cat /sys/kernel/debug/tracing/events/net/netif_rx/hist
1371
1372 # event histogram
1373 #
1374 # trigger info: hist:name=foo:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 [active]
1375 #
1376
1377 { skbaddr: ffff88000ad53500 } hitcount: 1 len: 46
1378 { skbaddr: ffff8800af5a1500 } hitcount: 1 len: 76
1379 { skbaddr: ffff8800d62a1900 } hitcount: 1 len: 46
1380 { skbaddr: ffff8800d2bccb00 } hitcount: 1 len: 468
1381 { skbaddr: ffff8800d3c69900 } hitcount: 1 len: 46
1382 { skbaddr: ffff88009ff09100 } hitcount: 1 len: 52
1383 { skbaddr: ffff88010f13ab00 } hitcount: 1 len: 168
1384 { skbaddr: ffff88006a54f400 } hitcount: 1 len: 46
1385 { skbaddr: ffff8800d2bcc500 } hitcount: 1 len: 260
1386 { skbaddr: ffff880064505000 } hitcount: 1 len: 46
1387 { skbaddr: ffff8800baf24e00 } hitcount: 1 len: 32
1388 { skbaddr: ffff88009fe0ad00 } hitcount: 1 len: 46
1389 { skbaddr: ffff8800d3edff00 } hitcount: 1 len: 44
1390 { skbaddr: ffff88009fe0b400 } hitcount: 1 len: 168
1391 { skbaddr: ffff8800a1c55a00 } hitcount: 1 len: 40
1392 { skbaddr: ffff8800d2bcd100 } hitcount: 1 len: 40
1393 { skbaddr: ffff880064505f00 } hitcount: 1 len: 174
1394 { skbaddr: ffff8800a8bff200 } hitcount: 1 len: 160
1395 { skbaddr: ffff880044e3cc00 } hitcount: 1 len: 76
1396 { skbaddr: ffff8800a8bfe700 } hitcount: 1 len: 46
1397 { skbaddr: ffff8800d2bcdc00 } hitcount: 1 len: 32
1398 { skbaddr: ffff8800a1f64800 } hitcount: 1 len: 46
1399 { skbaddr: ffff8800d2bcde00 } hitcount: 1 len: 988
1400 { skbaddr: ffff88006a5dea00 } hitcount: 1 len: 46
1401 { skbaddr: ffff88002e37a200 } hitcount: 1 len: 44
1402 { skbaddr: ffff8800a1f32c00 } hitcount: 2 len: 676
1403 { skbaddr: ffff88000ad52600 } hitcount: 2 len: 107
1404 { skbaddr: ffff8800a1f91e00 } hitcount: 2 len: 92
1405 { skbaddr: ffff8800af5a0200 } hitcount: 2 len: 142
1406 { skbaddr: ffff8800d2bcc600 } hitcount: 2 len: 220
1407 { skbaddr: ffff8800ba36f500 } hitcount: 2 len: 92
1408 { skbaddr: ffff8800d021f800 } hitcount: 2 len: 92
1409 { skbaddr: ffff8800a1f33600 } hitcount: 2 len: 675
1410 { skbaddr: ffff8800a8bfff00 } hitcount: 3 len: 138
1411 { skbaddr: ffff8800d62a1300 } hitcount: 3 len: 138
1412 { skbaddr: ffff88002e37a100 } hitcount: 4 len: 184
1413 { skbaddr: ffff880064504400 } hitcount: 4 len: 184
1414 { skbaddr: ffff8800a8bfec00 } hitcount: 4 len: 184
1415 { skbaddr: ffff88000ad53700 } hitcount: 5 len: 230
1416 { skbaddr: ffff8800d2bcdb00 } hitcount: 5 len: 196
1417 { skbaddr: ffff8800a1f90000 } hitcount: 6 len: 276
1418 { skbaddr: ffff88006a54f900 } hitcount: 6 len: 276
1419
1420 Totals:
1421 Hits: 81
1422 Entries: 42
1423 Dropped: 0
1424 # event histogram
1425 #
1426 # trigger info: hist:name=foo:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 [active]
1427 #
1428
1429 { skbaddr: ffff88000ad53500 } hitcount: 1 len: 46
1430 { skbaddr: ffff8800af5a1500 } hitcount: 1 len: 76
1431 { skbaddr: ffff8800d62a1900 } hitcount: 1 len: 46
1432 { skbaddr: ffff8800d2bccb00 } hitcount: 1 len: 468
1433 { skbaddr: ffff8800d3c69900 } hitcount: 1 len: 46
1434 { skbaddr: ffff88009ff09100 } hitcount: 1 len: 52
1435 { skbaddr: ffff88010f13ab00 } hitcount: 1 len: 168
1436 { skbaddr: ffff88006a54f400 } hitcount: 1 len: 46
1437 { skbaddr: ffff8800d2bcc500 } hitcount: 1 len: 260
1438 { skbaddr: ffff880064505000 } hitcount: 1 len: 46
1439 { skbaddr: ffff8800baf24e00 } hitcount: 1 len: 32
1440 { skbaddr: ffff88009fe0ad00 } hitcount: 1 len: 46
1441 { skbaddr: ffff8800d3edff00 } hitcount: 1 len: 44
1442 { skbaddr: ffff88009fe0b400 } hitcount: 1 len: 168
1443 { skbaddr: ffff8800a1c55a00 } hitcount: 1 len: 40
1444 { skbaddr: ffff8800d2bcd100 } hitcount: 1 len: 40
1445 { skbaddr: ffff880064505f00 } hitcount: 1 len: 174
1446 { skbaddr: ffff8800a8bff200 } hitcount: 1 len: 160
1447 { skbaddr: ffff880044e3cc00 } hitcount: 1 len: 76
1448 { skbaddr: ffff8800a8bfe700 } hitcount: 1 len: 46
1449 { skbaddr: ffff8800d2bcdc00 } hitcount: 1 len: 32
1450 { skbaddr: ffff8800a1f64800 } hitcount: 1 len: 46
1451 { skbaddr: ffff8800d2bcde00 } hitcount: 1 len: 988
1452 { skbaddr: ffff88006a5dea00 } hitcount: 1 len: 46
1453 { skbaddr: ffff88002e37a200 } hitcount: 1 len: 44
1454 { skbaddr: ffff8800a1f32c00 } hitcount: 2 len: 676
1455 { skbaddr: ffff88000ad52600 } hitcount: 2 len: 107
1456 { skbaddr: ffff8800a1f91e00 } hitcount: 2 len: 92
1457 { skbaddr: ffff8800af5a0200 } hitcount: 2 len: 142
1458 { skbaddr: ffff8800d2bcc600 } hitcount: 2 len: 220
1459 { skbaddr: ffff8800ba36f500 } hitcount: 2 len: 92
1460 { skbaddr: ffff8800d021f800 } hitcount: 2 len: 92
1461 { skbaddr: ffff8800a1f33600 } hitcount: 2 len: 675
1462 { skbaddr: ffff8800a8bfff00 } hitcount: 3 len: 138
1463 { skbaddr: ffff8800d62a1300 } hitcount: 3 len: 138
1464 { skbaddr: ffff88002e37a100 } hitcount: 4 len: 184
1465 { skbaddr: ffff880064504400 } hitcount: 4 len: 184
1466 { skbaddr: ffff8800a8bfec00 } hitcount: 4 len: 184
1467 { skbaddr: ffff88000ad53700 } hitcount: 5 len: 230
1468 { skbaddr: ffff8800d2bcdb00 } hitcount: 5 len: 196
1469 { skbaddr: ffff8800a1f90000 } hitcount: 6 len: 276
1470 { skbaddr: ffff88006a54f900 } hitcount: 6 len: 276
1471
1472 Totals:
1473 Hits: 81
1474 Entries: 42
1475 Dropped: 0
1476
1477 And here's an example that shows how to combine histogram data from
1478 any two events even if they don't share any 'compatible' fields
1479 other than 'hitcount' and 'stacktrace'. These commands create a
ea272257 1480 couple of triggers named 'bar' using those fields::
b8df4a36
TZ
1481
1482 # echo 'hist:name=bar:key=stacktrace:val=hitcount' > \
1483 /sys/kernel/debug/tracing/events/sched/sched_process_fork/trigger
1484 # echo 'hist:name=bar:key=stacktrace:val=hitcount' > \
1485 /sys/kernel/debug/tracing/events/net/netif_rx/trigger
1486
1487 And displaying the output of either shows some interesting if
ea272257 1488 somewhat confusing output::
b8df4a36
TZ
1489
1490 # cat /sys/kernel/debug/tracing/events/sched/sched_process_fork/hist
1491 # cat /sys/kernel/debug/tracing/events/net/netif_rx/hist
1492
1493 # event histogram
1494 #
1495 # trigger info: hist:name=bar:keys=stacktrace:vals=hitcount:sort=hitcount:size=2048 [active]
1496 #
1497
1498 { stacktrace:
eea11285 1499 kernel_clone+0x18e/0x330
b8df4a36
TZ
1500 kernel_thread+0x29/0x30
1501 kthreadd+0x154/0x1b0
1502 ret_from_fork+0x3f/0x70
1503 } hitcount: 1
1504 { stacktrace:
1505 netif_rx_internal+0xb2/0xd0
1506 netif_rx_ni+0x20/0x70
1507 dev_loopback_xmit+0xaa/0xd0
1508 ip_mc_output+0x126/0x240
1509 ip_local_out_sk+0x31/0x40
1510 igmp_send_report+0x1e9/0x230
1511 igmp_timer_expire+0xe9/0x120
1512 call_timer_fn+0x39/0xf0
1513 run_timer_softirq+0x1e1/0x290
1514 __do_softirq+0xfd/0x290
1515 irq_exit+0x98/0xb0
1516 smp_apic_timer_interrupt+0x4a/0x60
1517 apic_timer_interrupt+0x6d/0x80
1518 cpuidle_enter+0x17/0x20
1519 call_cpuidle+0x3b/0x60
1520 cpu_startup_entry+0x22d/0x310
1521 } hitcount: 1
1522 { stacktrace:
1523 netif_rx_internal+0xb2/0xd0
1524 netif_rx_ni+0x20/0x70
1525 dev_loopback_xmit+0xaa/0xd0
1526 ip_mc_output+0x17f/0x240
1527 ip_local_out_sk+0x31/0x40
1528 ip_send_skb+0x1a/0x50
1529 udp_send_skb+0x13e/0x270
1530 udp_sendmsg+0x2bf/0x980
1531 inet_sendmsg+0x67/0xa0
1532 sock_sendmsg+0x38/0x50
1533 SYSC_sendto+0xef/0x170
1534 SyS_sendto+0xe/0x10
1535 entry_SYSCALL_64_fastpath+0x12/0x6a
1536 } hitcount: 2
1537 { stacktrace:
1538 netif_rx_internal+0xb2/0xd0
1539 netif_rx+0x1c/0x60
1540 loopback_xmit+0x6c/0xb0
1541 dev_hard_start_xmit+0x219/0x3a0
1542 __dev_queue_xmit+0x415/0x4f0
1543 dev_queue_xmit_sk+0x13/0x20
1544 ip_finish_output2+0x237/0x340
1545 ip_finish_output+0x113/0x1d0
1546 ip_output+0x66/0xc0
1547 ip_local_out_sk+0x31/0x40
1548 ip_send_skb+0x1a/0x50
1549 udp_send_skb+0x16d/0x270
1550 udp_sendmsg+0x2bf/0x980
1551 inet_sendmsg+0x67/0xa0
1552 sock_sendmsg+0x38/0x50
1553 ___sys_sendmsg+0x14e/0x270
1554 } hitcount: 76
1555 { stacktrace:
1556 netif_rx_internal+0xb2/0xd0
1557 netif_rx+0x1c/0x60
1558 loopback_xmit+0x6c/0xb0
1559 dev_hard_start_xmit+0x219/0x3a0
1560 __dev_queue_xmit+0x415/0x4f0
1561 dev_queue_xmit_sk+0x13/0x20
1562 ip_finish_output2+0x237/0x340
1563 ip_finish_output+0x113/0x1d0
1564 ip_output+0x66/0xc0
1565 ip_local_out_sk+0x31/0x40
1566 ip_send_skb+0x1a/0x50
1567 udp_send_skb+0x16d/0x270
1568 udp_sendmsg+0x2bf/0x980
1569 inet_sendmsg+0x67/0xa0
1570 sock_sendmsg+0x38/0x50
1571 ___sys_sendmsg+0x269/0x270
1572 } hitcount: 77
1573 { stacktrace:
1574 netif_rx_internal+0xb2/0xd0
1575 netif_rx+0x1c/0x60
1576 loopback_xmit+0x6c/0xb0
1577 dev_hard_start_xmit+0x219/0x3a0
1578 __dev_queue_xmit+0x415/0x4f0
1579 dev_queue_xmit_sk+0x13/0x20
1580 ip_finish_output2+0x237/0x340
1581 ip_finish_output+0x113/0x1d0
1582 ip_output+0x66/0xc0
1583 ip_local_out_sk+0x31/0x40
1584 ip_send_skb+0x1a/0x50
1585 udp_send_skb+0x16d/0x270
1586 udp_sendmsg+0x2bf/0x980
1587 inet_sendmsg+0x67/0xa0
1588 sock_sendmsg+0x38/0x50
1589 SYSC_sendto+0xef/0x170
1590 } hitcount: 88
1591 { stacktrace:
eea11285 1592 kernel_clone+0x18e/0x330
b8df4a36
TZ
1593 SyS_clone+0x19/0x20
1594 entry_SYSCALL_64_fastpath+0x12/0x6a
1595 } hitcount: 244
1596
1597 Totals:
1598 Hits: 489
1599 Entries: 7
1600 Dropped: 0
033cbcee 1601
033cbcee
TZ
16022.2 Inter-event hist triggers
1603-----------------------------
1604
1605Inter-event hist triggers are hist triggers that combine values from
1606one or more other events and create a histogram using that data. Data
1607from an inter-event histogram can in turn become the source for
1608further combined histograms, thus providing a chain of related
1609histograms, which is important for some applications.
1610
1611The most important example of an inter-event quantity that can be used
1612in this manner is latency, which is simply a difference in timestamps
1613between two events. Although latency is the most important
1614inter-event quantity, note that because the support is completely
1615general across the trace event subsystem, any event field can be used
1616in an inter-event quantity.
1617
1618An example of a histogram that combines data from other histograms
1619into a useful chain would be a 'wakeupswitch latency' histogram that
1620combines a 'wakeup latency' histogram and a 'switch latency'
1621histogram.
1622
1623Normally, a hist trigger specification consists of a (possibly
1624compound) key along with one or more numeric values, which are
1625continually updated sums associated with that key. A histogram
1626specification in this case consists of individual key and value
1627specifications that refer to trace event fields associated with a
1628single event type.
1629
1630The inter-event hist trigger extension allows fields from multiple
1631events to be referenced and combined into a multi-event histogram
1632specification. In support of this overall goal, a few enabling
1633features have been added to the hist trigger support:
1634
1635 - In order to compute an inter-event quantity, a value from one
1636 event needs to saved and then referenced from another event. This
1637 requires the introduction of support for histogram 'variables'.
1638
1639 - The computation of inter-event quantities and their combination
1640 require some minimal amount of support for applying simple
1641 expressions to variables (+ and -).
1642
1643 - A histogram consisting of inter-event quantities isn't logically a
1644 histogram on either event (so having the 'hist' file for either
1645 event host the histogram output doesn't really make sense). To
1646 address the idea that the histogram is associated with a
1647 combination of events, support is added allowing the creation of
1648 'synthetic' events that are events derived from other events.
1649 These synthetic events are full-fledged events just like any other
1650 and can be used as such, as for instance to create the
1651 'combination' histograms mentioned previously.
1652
1653 - A set of 'actions' can be associated with histogram entries -
1654 these can be used to generate the previously mentioned synthetic
1655 events, but can also be used for other purposes, such as for
1656 example saving context when a 'max' latency has been hit.
1657
1658 - Trace events don't have a 'timestamp' associated with them, but
1659 there is an implicit timestamp saved along with an event in the
1660 underlying ftrace ring buffer. This timestamp is now exposed as a
1661 a synthetic field named 'common_timestamp' which can be used in
1662 histograms as if it were any other event field; it isn't an actual
1663 field in the trace format but rather is a synthesized value that
1664 nonetheless can be used as if it were an actual field. By default
1665 it is in units of nanoseconds; appending '.usecs' to a
1666 common_timestamp field changes the units to microseconds.
1667
a4072fe8
TZ
1668A note on inter-event timestamps: If common_timestamp is used in a
1669histogram, the trace buffer is automatically switched over to using
1670absolute timestamps and the "global" trace clock, in order to avoid
1671bogus timestamp differences with other clocks that aren't coherent
1672across CPUs. This can be overridden by specifying one of the other
1673trace clocks instead, using the "clock=XXX" hist trigger attribute,
1674where XXX is any of the clocks listed in the tracing/trace_clock
1675pseudo-file.
1676
1677These features are described in more detail in the following sections.
033cbcee
TZ
1678
16792.2.1 Histogram Variables
1680-------------------------
1681
1682Variables are simply named locations used for saving and retrieving
1683values between matching events. A 'matching' event is defined as an
1684event that has a matching key - if a variable is saved for a histogram
1685entry corresponding to that key, any subsequent event with a matching
1686key can access that variable.
1687
1688A variable's value is normally available to any subsequent event until
1689it is set to something else by a subsequent event. The one exception
1690to that rule is that any variable used in an expression is essentially
1691'read-once' - once it's used by an expression in a subsequent event,
1692it's reset to its 'unset' state, which means it can't be used again
1693unless it's set again. This ensures not only that an event doesn't
1694use an uninitialized variable in a calculation, but that that variable
1695is used only once and not for any unrelated subsequent match.
1696
1697The basic syntax for saving a variable is to simply prefix a unique
1698variable name not corresponding to any keyword along with an '=' sign
1699to any event field.
1700
1701Either keys or values can be saved and retrieved in this way. This
1702creates a variable named 'ts0' for a histogram entry with the key
ea272257 1703'next_pid'::
033cbcee
TZ
1704
1705 # echo 'hist:keys=next_pid:vals=$ts0:ts0=common_timestamp ... >> \
1706 event/trigger
1707
1708The ts0 variable can be accessed by any subsequent event having the
1709same pid as 'next_pid'.
1710
1711Variable references are formed by prepending the variable name with
1712the '$' sign. Thus for example, the ts0 variable above would be
1713referenced as '$ts0' in expressions.
1714
1715Because 'vals=' is used, the common_timestamp variable value above
1716will also be summed as a normal histogram value would (though for a
1717timestamp it makes little sense).
1718
ea272257 1719The below shows that a key value can also be saved in the same way::
033cbcee
TZ
1720
1721 # echo 'hist:timer_pid=common_pid:key=timer_pid ...' >> event/trigger
1722
1723If a variable isn't a key variable or prefixed with 'vals=', the
1724associated event field will be saved in a variable but won't be summed
ea272257 1725as a value::
033cbcee 1726
064f35a9 1727 # echo 'hist:keys=next_pid:ts1=common_timestamp ...' >> event/trigger
033cbcee
TZ
1728
1729Multiple variables can be assigned at the same time. The below would
1730result in both ts0 and b being created as variables, with both
ea272257 1731common_timestamp and field1 additionally being summed as values::
033cbcee 1732
064f35a9 1733 # echo 'hist:keys=pid:vals=$ts0,$b:ts0=common_timestamp,b=field1 ...' >> \
033cbcee
TZ
1734 event/trigger
1735
1736Note that variable assignments can appear either preceding or
1737following their use. The command below behaves identically to the
ea272257 1738command above::
033cbcee 1739
064f35a9 1740 # echo 'hist:keys=pid:ts0=common_timestamp,b=field1:vals=$ts0,$b ...' >> \
033cbcee
TZ
1741 event/trigger
1742
1743Any number of variables not bound to a 'vals=' prefix can also be
1744assigned by simply separating them with colons. Below is the same
ea272257 1745thing but without the values being summed in the histogram::
033cbcee 1746
064f35a9 1747 # echo 'hist:keys=pid:ts0=common_timestamp:b=field1 ...' >> event/trigger
033cbcee
TZ
1748
1749Variables set as above can be referenced and used in expressions on
1750another event.
1751
ea272257 1752For example, here's how a latency can be calculated::
033cbcee 1753
064f35a9
JFG
1754 # echo 'hist:keys=pid,prio:ts0=common_timestamp ...' >> event1/trigger
1755 # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp-$ts0 ...' >> event2/trigger
033cbcee 1756
aea74de4 1757In the first line above, the event's timestamp is saved into the
033cbcee
TZ
1758variable ts0. In the next line, ts0 is subtracted from the second
1759event's timestamp to produce the latency, which is then assigned into
1760yet another variable, 'wakeup_lat'. The hist trigger below in turn
1761makes use of the wakeup_lat variable to compute a combined latency
ea272257 1762using the same key and variable from yet another event::
033cbcee 1763
064f35a9 1764 # echo 'hist:key=pid:wakeupswitch_lat=$wakeup_lat+$switchtime_lat ...' >> event3/trigger
033cbcee
TZ
1765
17662.2.2 Synthetic Events
1767----------------------
1768
1769Synthetic events are user-defined events generated from hist trigger
1770variables or fields associated with one or more other events. Their
1771purpose is to provide a mechanism for displaying data spanning
1772multiple events consistent with the existing and already familiar
1773usage for normal events.
1774
1775To define a synthetic event, the user writes a simple specification
1776consisting of the name of the new event along with one or more
1777variables and their types, which can be any valid field type,
1778separated by semicolons, to the tracing/synthetic_events file.
1779
bd82631d
TZ
1780See synth_field_size() for available types.
1781
1782If field_name contains [n], the field is considered to be a static array.
1783
1784If field_names contains[] (no subscript), the field is considered to
1785be a dynamic array, which will only take as much space in the event as
1786is required to hold the array.
1787
1788A string field can be specified using either the static notation:
1789
1790 char name[32];
1791
1792Or the dynamic:
1793
1794 char name[];
1795
1796The size limit for either is 256.
1797
033cbcee
TZ
1798For instance, the following creates a new event named 'wakeup_latency'
1799with 3 fields: lat, pid, and prio. Each of those fields is simply a
ea272257 1800variable reference to a variable on another event::
033cbcee
TZ
1801
1802 # echo 'wakeup_latency \
1803 u64 lat; \
1804 pid_t pid; \
1805 int prio' >> \
1806 /sys/kernel/debug/tracing/synthetic_events
1807
1808Reading the tracing/synthetic_events file lists all the currently
ea272257 1809defined synthetic events, in this case the event defined above::
033cbcee
TZ
1810
1811 # cat /sys/kernel/debug/tracing/synthetic_events
1812 wakeup_latency u64 lat; pid_t pid; int prio
1813
1814An existing synthetic event definition can be removed by prepending
ea272257 1815the command that defined it with a '!'::
033cbcee
TZ
1816
1817 # echo '!wakeup_latency u64 lat pid_t pid int prio' >> \
1818 /sys/kernel/debug/tracing/synthetic_events
1819
1820At this point, there isn't yet an actual 'wakeup_latency' event
aea74de4 1821instantiated in the event subsystem - for this to happen, a 'hist
033cbcee 1822trigger action' needs to be instantiated and bound to actual fields
064f35a9
JFG
1823and variables defined on other events (see Section 2.2.3 below on
1824how that is done using hist trigger 'onmatch' action). Once that is
1825done, the 'wakeup_latency' synthetic event instance is created.
033cbcee 1826
033cbcee 1827The new event is created under the tracing/events/synthetic/ directory
ea272257 1828and looks and behaves just like any other event::
033cbcee
TZ
1829
1830 # ls /sys/kernel/debug/tracing/events/synthetic/wakeup_latency
1831 enable filter format hist id trigger
1832
37036435
SRV
1833A histogram can now be defined for the new synthetic event::
1834
1835 # echo 'hist:keys=pid,prio,lat.log2:sort=lat' >> \
1836 /sys/kernel/debug/tracing/events/synthetic/wakeup_latency/trigger
1837
1838The above shows the latency "lat" in a power of 2 grouping.
1839
033cbcee
TZ
1840Like any other event, once a histogram is enabled for the event, the
1841output can be displayed by reading the event's 'hist' file.
1842
37036435
SRV
1843 # cat /sys/kernel/debug/tracing/events/synthetic/wakeup_latency/hist
1844
1845 # event histogram
1846 #
1847 # trigger info: hist:keys=pid,prio,lat.log2:vals=hitcount:sort=lat.log2:size=2048 [active]
1848 #
1849
1850 { pid: 2035, prio: 9, lat: ~ 2^2 } hitcount: 43
1851 { pid: 2034, prio: 9, lat: ~ 2^2 } hitcount: 60
1852 { pid: 2029, prio: 9, lat: ~ 2^2 } hitcount: 965
1853 { pid: 2034, prio: 120, lat: ~ 2^2 } hitcount: 9
1854 { pid: 2033, prio: 120, lat: ~ 2^2 } hitcount: 5
1855 { pid: 2030, prio: 9, lat: ~ 2^2 } hitcount: 335
1856 { pid: 2030, prio: 120, lat: ~ 2^2 } hitcount: 10
1857 { pid: 2032, prio: 120, lat: ~ 2^2 } hitcount: 1
1858 { pid: 2035, prio: 120, lat: ~ 2^2 } hitcount: 2
1859 { pid: 2031, prio: 9, lat: ~ 2^2 } hitcount: 176
1860 { pid: 2028, prio: 120, lat: ~ 2^2 } hitcount: 15
1861 { pid: 2033, prio: 9, lat: ~ 2^2 } hitcount: 91
1862 { pid: 2032, prio: 9, lat: ~ 2^2 } hitcount: 125
1863 { pid: 2029, prio: 120, lat: ~ 2^2 } hitcount: 4
1864 { pid: 2031, prio: 120, lat: ~ 2^2 } hitcount: 3
1865 { pid: 2029, prio: 120, lat: ~ 2^3 } hitcount: 2
1866 { pid: 2035, prio: 9, lat: ~ 2^3 } hitcount: 41
1867 { pid: 2030, prio: 120, lat: ~ 2^3 } hitcount: 1
1868 { pid: 2032, prio: 9, lat: ~ 2^3 } hitcount: 32
1869 { pid: 2031, prio: 9, lat: ~ 2^3 } hitcount: 44
1870 { pid: 2034, prio: 9, lat: ~ 2^3 } hitcount: 40
1871 { pid: 2030, prio: 9, lat: ~ 2^3 } hitcount: 29
1872 { pid: 2033, prio: 9, lat: ~ 2^3 } hitcount: 31
1873 { pid: 2029, prio: 9, lat: ~ 2^3 } hitcount: 31
1874 { pid: 2028, prio: 120, lat: ~ 2^3 } hitcount: 18
1875 { pid: 2031, prio: 120, lat: ~ 2^3 } hitcount: 2
1876 { pid: 2028, prio: 120, lat: ~ 2^4 } hitcount: 1
1877 { pid: 2029, prio: 9, lat: ~ 2^4 } hitcount: 4
1878 { pid: 2031, prio: 120, lat: ~ 2^7 } hitcount: 1
1879 { pid: 2032, prio: 120, lat: ~ 2^7 } hitcount: 1
1880
1881 Totals:
1882 Hits: 2122
1883 Entries: 30
1884 Dropped: 0
1885
1886
1887The latency values can also be grouped linearly by a given size with
1888the ".buckets" modifier and specify a size (in this case groups of 10).
1889
1890 # echo 'hist:keys=pid,prio,lat.buckets=10:sort=lat' >> \
1891 /sys/kernel/debug/tracing/events/synthetic/wakeup_latency/trigger
1892
1893 # event histogram
1894 #
1895 # trigger info: hist:keys=pid,prio,lat.buckets=10:vals=hitcount:sort=lat.buckets=10:size=2048 [active]
1896 #
1897
1898 { pid: 2067, prio: 9, lat: ~ 0-9 } hitcount: 220
1899 { pid: 2068, prio: 9, lat: ~ 0-9 } hitcount: 157
1900 { pid: 2070, prio: 9, lat: ~ 0-9 } hitcount: 100
1901 { pid: 2067, prio: 120, lat: ~ 0-9 } hitcount: 6
1902 { pid: 2065, prio: 120, lat: ~ 0-9 } hitcount: 2
1903 { pid: 2066, prio: 120, lat: ~ 0-9 } hitcount: 2
1904 { pid: 2069, prio: 9, lat: ~ 0-9 } hitcount: 122
1905 { pid: 2069, prio: 120, lat: ~ 0-9 } hitcount: 8
1906 { pid: 2070, prio: 120, lat: ~ 0-9 } hitcount: 1
1907 { pid: 2068, prio: 120, lat: ~ 0-9 } hitcount: 7
1908 { pid: 2066, prio: 9, lat: ~ 0-9 } hitcount: 365
1909 { pid: 2064, prio: 120, lat: ~ 0-9 } hitcount: 35
1910 { pid: 2065, prio: 9, lat: ~ 0-9 } hitcount: 998
1911 { pid: 2071, prio: 9, lat: ~ 0-9 } hitcount: 85
1912 { pid: 2065, prio: 9, lat: ~ 10-19 } hitcount: 2
1913 { pid: 2064, prio: 120, lat: ~ 10-19 } hitcount: 2
1914
1915 Totals:
1916 Hits: 2112
1917 Entries: 16
1918 Dropped: 0
1919
5032b381
TZ
19202.2.3 Hist trigger 'handlers' and 'actions'
1921-------------------------------------------
033cbcee 1922
5032b381
TZ
1923A hist trigger 'action' is a function that's executed (in most cases
1924conditionally) whenever a histogram entry is added or updated.
033cbcee 1925
5032b381
TZ
1926When a histogram entry is added or updated, a hist trigger 'handler'
1927is what decides whether the corresponding action is actually invoked
1928or not.
033cbcee 1929
5032b381
TZ
1930Hist trigger handlers and actions are paired together in the general
1931form:
1932
1933 <handler>.<action>
1934
1935To specify a handler.action pair for a given event, simply specify
1936that handler.action pair between colons in the hist trigger
1937specification.
1938
1939In theory, any handler can be combined with any action, but in
1940practice, not every handler.action combination is currently supported;
1941if a given handler.action combination isn't supported, the hist
1942trigger will fail with -EINVAL;
1943
fe4ec72c 1944The default 'handler.action' if none is explicitly specified is as it
5032b381
TZ
1945always has been, to simply update the set of values associated with an
1946entry. Some applications, however, may want to perform additional
1947actions at that point, such as generate another event, or compare and
1948save a maximum.
1949
1950The supported handlers and actions are listed below, and each is
1951described in more detail in the following paragraphs, in the context
1952of descriptions of some common and useful handler.action combinations.
1953
1954The available handlers are:
1955
1956 - onmatch(matching.event) - invoke action on any addition or update
1957 - onmax(var) - invoke action if var exceeds current max
ff0d35e2 1958 - onchange(var) - invoke action if var changes
5032b381
TZ
1959
1960The available actions are:
1961
e91eefd7 1962 - trace(<synthetic_event_name>,param list) - generate synthetic event
5032b381 1963 - save(field,...) - save current event fields
fd451a3d 1964 - snapshot() - snapshot the trace buffer
5032b381
TZ
1965
1966The following commonly-used handler.action pairs are available:
033cbcee 1967
e91eefd7 1968 - onmatch(matching.event).trace(<synthetic_event_name>,param list)
033cbcee 1969
e91eefd7
TZ
1970 The 'onmatch(matching.event).trace(<synthetic_event_name>,param
1971 list)' hist trigger action is invoked whenever an event matches
1972 and the histogram entry would be added or updated. It causes the
1973 named synthetic event to be generated with the values given in the
033cbcee
TZ
1974 'param list'. The result is the generation of a synthetic event
1975 that consists of the values contained in those variables at the
e91eefd7
TZ
1976 time the invoking event was hit. For example, if the synthetic
1977 event name is 'wakeup_latency', a wakeup_latency event is
1978 generated using onmatch(event).trace(wakeup_latency,arg1,arg2).
1979
1980 There is also an equivalent alternative form available for
1981 generating synthetic events. In this form, the synthetic event
1982 name is used as if it were a function name. For example, using
1983 the 'wakeup_latency' synthetic event name again, the
1984 wakeup_latency event would be generated by invoking it as if it
1985 were a function call, with the event field values passed in as
1986 arguments: onmatch(event).wakeup_latency(arg1,arg2). The syntax
1987 for this form is:
1988
1989 onmatch(matching.event).<synthetic_event_name>(param list)
1990
1991 In either case, the 'param list' consists of one or more
1992 parameters which may be either variables or fields defined on
1993 either the 'matching.event' or the target event. The variables or
1994 fields specified in the param list may be either fully-qualified
1995 or unqualified. If a variable is specified as unqualified, it
1996 must be unique between the two events. A field name used as a
1997 param can be unqualified if it refers to the target event, but
1998 must be fully qualified if it refers to the matching event. A
1999 fully-qualified name is of the form 'system.event_name.$var_name'
2000 or 'system.event_name.field'.
033cbcee
TZ
2001
2002 The 'matching.event' specification is simply the fully qualified
2003 event name of the event that matches the target event for the
39a39d5b
TS
2004 onmatch() functionality, in the form 'system.event_name'. Histogram
2005 keys of both events are compared to find if events match. In case
2006 multiple histogram keys are used, they all must match in the specified
2007 order.
033cbcee
TZ
2008
2009 Finally, the number and type of variables/fields in the 'param
2010 list' must match the number and types of the fields in the
2011 synthetic event being generated.
2012
2013 As an example the below defines a simple synthetic event and uses
2014 a variable defined on the sched_wakeup_new event as a parameter
2015 when invoking the synthetic event. Here we define the synthetic
ea272257 2016 event::
033cbcee 2017
ea272257
MCC
2018 # echo 'wakeup_new_test pid_t pid' >> \
2019 /sys/kernel/debug/tracing/synthetic_events
033cbcee 2020
ea272257
MCC
2021 # cat /sys/kernel/debug/tracing/synthetic_events
2022 wakeup_new_test pid_t pid
033cbcee
TZ
2023
2024 The following hist trigger both defines the missing testpid
2025 variable and specifies an onmatch() action that generates a
2026 wakeup_new_test synthetic event whenever a sched_wakeup_new event
2027 occurs, which because of the 'if comm == "cyclictest"' filter only
ea272257 2028 happens when the executable is cyclictest::
033cbcee 2029
ea272257
MCC
2030 # echo 'hist:keys=$testpid:testpid=pid:onmatch(sched.sched_wakeup_new).\
2031 wakeup_new_test($testpid) if comm=="cyclictest"' >> \
2032 /sys/kernel/debug/tracing/events/sched/sched_wakeup_new/trigger
033cbcee 2033
e91eefd7
TZ
2034 Or, equivalently, using the 'trace' keyword syntax:
2035
2036 # echo 'hist:keys=$testpid:testpid=pid:onmatch(sched.sched_wakeup_new).\
2037 trace(wakeup_new_test,$testpid) if comm=="cyclictest"' >> \
2038 /sys/kernel/debug/tracing/events/sched/sched_wakeup_new/trigger
2039
033cbcee
TZ
2040 Creating and displaying a histogram based on those events is now
2041 just a matter of using the fields and new synthetic event in the
ea272257 2042 tracing/events/synthetic directory, as usual::
033cbcee 2043
ea272257
MCC
2044 # echo 'hist:keys=pid:sort=pid' >> \
2045 /sys/kernel/debug/tracing/events/synthetic/wakeup_new_test/trigger
033cbcee
TZ
2046
2047 Running 'cyclictest' should cause wakeup_new events to generate
2048 wakeup_new_test synthetic events which should result in histogram
ea272257 2049 output in the wakeup_new_test event's hist file::
033cbcee 2050
ea272257 2051 # cat /sys/kernel/debug/tracing/events/synthetic/wakeup_new_test/hist
033cbcee
TZ
2052
2053 A more typical usage would be to use two events to calculate a
2054 latency. The following example uses a set of hist triggers to
ea272257 2055 produce a 'wakeup_latency' histogram.
033cbcee 2056
ea272257 2057 First, we define a 'wakeup_latency' synthetic event::
033cbcee 2058
ea272257
MCC
2059 # echo 'wakeup_latency u64 lat; pid_t pid; int prio' >> \
2060 /sys/kernel/debug/tracing/synthetic_events
033cbcee
TZ
2061
2062 Next, we specify that whenever we see a sched_waking event for a
ea272257 2063 cyclictest thread, save the timestamp in a 'ts0' variable::
033cbcee 2064
ea272257
MCC
2065 # echo 'hist:keys=$saved_pid:saved_pid=pid:ts0=common_timestamp.usecs \
2066 if comm=="cyclictest"' >> \
2067 /sys/kernel/debug/tracing/events/sched/sched_waking/trigger
033cbcee
TZ
2068
2069 Then, when the corresponding thread is actually scheduled onto the
39a39d5b
TS
2070 CPU by a sched_switch event (saved_pid matches next_pid), calculate
2071 the latency and use that along with another variable and an event field
2072 to generate a wakeup_latency synthetic event::
033cbcee 2073
ea272257
MCC
2074 # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0:\
2075 onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,\
2076 $saved_pid,next_prio) if next_comm=="cyclictest"' >> \
2077 /sys/kernel/debug/tracing/events/sched/sched_switch/trigger
033cbcee
TZ
2078
2079 We also need to create a histogram on the wakeup_latency synthetic
ea272257 2080 event in order to aggregate the generated synthetic event data::
033cbcee 2081
ea272257
MCC
2082 # echo 'hist:keys=pid,prio,lat:sort=pid,lat' >> \
2083 /sys/kernel/debug/tracing/events/synthetic/wakeup_latency/trigger
033cbcee
TZ
2084
2085 Finally, once we've run cyclictest to actually generate some
2086 events, we can see the output by looking at the wakeup_latency
ea272257 2087 synthetic event's hist file::
033cbcee 2088
ea272257 2089 # cat /sys/kernel/debug/tracing/events/synthetic/wakeup_latency/hist
033cbcee
TZ
2090
2091 - onmax(var).save(field,.. .)
2092
2093 The 'onmax(var).save(field,...)' hist trigger action is invoked
2094 whenever the value of 'var' associated with a histogram entry
2095 exceeds the current maximum contained in that variable.
2096
2097 The end result is that the trace event fields specified as the
2098 onmax.save() params will be saved if 'var' exceeds the current
2099 maximum for that hist trigger entry. This allows context from the
2100 event that exhibited the new maximum to be saved for later
2101 reference. When the histogram is displayed, additional fields
2102 displaying the saved values will be printed.
2103
2104 As an example the below defines a couple of hist triggers, one for
2105 sched_waking and another for sched_switch, keyed on pid. Whenever
2106 a sched_waking occurs, the timestamp is saved in the entry
2107 corresponding to the current pid, and when the scheduler switches
2108 back to that pid, the timestamp difference is calculated. If the
2109 resulting latency, stored in wakeup_lat, exceeds the current
2110 maximum latency, the values specified in the save() fields are
ea272257 2111 recorded::
033cbcee 2112
ea272257
MCC
2113 # echo 'hist:keys=pid:ts0=common_timestamp.usecs \
2114 if comm=="cyclictest"' >> \
2115 /sys/kernel/debug/tracing/events/sched/sched_waking/trigger
033cbcee 2116
ea272257
MCC
2117 # echo 'hist:keys=next_pid:\
2118 wakeup_lat=common_timestamp.usecs-$ts0:\
2119 onmax($wakeup_lat).save(next_comm,prev_pid,prev_prio,prev_comm) \
2120 if next_comm=="cyclictest"' >> \
2121 /sys/kernel/debug/tracing/events/sched/sched_switch/trigger
033cbcee
TZ
2122
2123 When the histogram is displayed, the max value and the saved
2124 values corresponding to the max are displayed following the rest
ea272257 2125 of the fields::
033cbcee 2126
ea272257
MCC
2127 # cat /sys/kernel/debug/tracing/events/sched/sched_switch/hist
2128 { next_pid: 2255 } hitcount: 239
2129 common_timestamp-ts0: 0
2130 max: 27
2131 next_comm: cyclictest
2132 prev_pid: 0 prev_prio: 120 prev_comm: swapper/1
033cbcee 2133
ea272257
MCC
2134 { next_pid: 2256 } hitcount: 2355
2135 common_timestamp-ts0: 0
2136 max: 49 next_comm: cyclictest
2137 prev_pid: 0 prev_prio: 120 prev_comm: swapper/0
033cbcee 2138
ea272257
MCC
2139 Totals:
2140 Hits: 12970
2141 Entries: 2
2142 Dropped: 0
d3439f9d 2143
fd451a3d
TZ
2144 - onmax(var).snapshot()
2145
2146 The 'onmax(var).snapshot()' hist trigger action is invoked
2147 whenever the value of 'var' associated with a histogram entry
2148 exceeds the current maximum contained in that variable.
2149
2150 The end result is that a global snapshot of the trace buffer will
2151 be saved in the tracing/snapshot file if 'var' exceeds the current
2152 maximum for any hist trigger entry.
2153
2154 Note that in this case the maximum is a global maximum for the
2155 current trace instance, which is the maximum across all buckets of
2156 the histogram. The key of the specific trace event that caused
2157 the global maximum and the global maximum itself are displayed,
2158 along with a message stating that a snapshot has been taken and
2159 where to find it. The user can use the key information displayed
2160 to locate the corresponding bucket in the histogram for even more
2161 detail.
2162
2163 As an example the below defines a couple of hist triggers, one for
2164 sched_waking and another for sched_switch, keyed on pid. Whenever
2165 a sched_waking event occurs, the timestamp is saved in the entry
2166 corresponding to the current pid, and when the scheduler switches
2167 back to that pid, the timestamp difference is calculated. If the
2168 resulting latency, stored in wakeup_lat, exceeds the current
2169 maximum latency, a snapshot is taken. As part of the setup, all
2170 the scheduler events are also enabled, which are the events that
2171 will show up in the snapshot when it is taken at some point:
2172
2173 # echo 1 > /sys/kernel/debug/tracing/events/sched/enable
2174
2175 # echo 'hist:keys=pid:ts0=common_timestamp.usecs \
2176 if comm=="cyclictest"' >> \
2177 /sys/kernel/debug/tracing/events/sched/sched_waking/trigger
2178
2179 # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0: \
2180 onmax($wakeup_lat).save(next_prio,next_comm,prev_pid,prev_prio, \
2181 prev_comm):onmax($wakeup_lat).snapshot() \
2182 if next_comm=="cyclictest"' >> \
2183 /sys/kernel/debug/tracing/events/sched/sched_switch/trigger
2184
2185 When the histogram is displayed, for each bucket the max value
2186 and the saved values corresponding to the max are displayed
2187 following the rest of the fields.
2188
fe4ec72c 2189 If a snapshot was taken, there is also a message indicating that,
fd451a3d
TZ
2190 along with the value and event that triggered the global maximum:
2191
2192 # cat /sys/kernel/debug/tracing/events/sched/sched_switch/hist
2193 { next_pid: 2101 } hitcount: 200
2194 max: 52 next_prio: 120 next_comm: cyclictest \
2195 prev_pid: 0 prev_prio: 120 prev_comm: swapper/6
2196
2197 { next_pid: 2103 } hitcount: 1326
2198 max: 572 next_prio: 19 next_comm: cyclictest \
2199 prev_pid: 0 prev_prio: 120 prev_comm: swapper/1
2200
2201 { next_pid: 2102 } hitcount: 1982 \
2202 max: 74 next_prio: 19 next_comm: cyclictest \
2203 prev_pid: 0 prev_prio: 120 prev_comm: swapper/5
2204
2205 Snapshot taken (see tracing/snapshot). Details:
2206 triggering value { onmax($wakeup_lat) }: 572 \
2207 triggered by event with key: { next_pid: 2103 }
2208
2209 Totals:
2210 Hits: 3508
2211 Entries: 3
2212 Dropped: 0
2213
2214 In the above case, the event that triggered the global maximum has
2215 the key with next_pid == 2103. If you look at the bucket that has
2216 2103 as the key, you'll find the additional values save()'d along
2217 with the local maximum for that bucket, which should be the same
2218 as the global maximum (since that was the same value that
2219 triggered the global snapshot).
2220
2221 And finally, looking at the snapshot data should show at or near
2222 the end the event that triggered the snapshot (in this case you
2223 can verify the timestamps between the sched_waking and
2224 sched_switch events, which should match the time displayed in the
3df5ffd2
MCC
2225 global maximum)::
2226
2227 # cat /sys/kernel/debug/tracing/snapshot
2228
2229 <...>-2103 [005] d..3 309.873125: sched_switch: prev_comm=cyclictest prev_pid=2103 prev_prio=19 prev_state=D ==> next_comm=swapper/5 next_pid=0 next_prio=120
2230 <idle>-0 [005] d.h3 309.873611: sched_waking: comm=cyclictest pid=2102 prio=19 target_cpu=005
2231 <idle>-0 [005] dNh4 309.873613: sched_wakeup: comm=cyclictest pid=2102 prio=19 target_cpu=005
2232 <idle>-0 [005] d..3 309.873616: sched_switch: prev_comm=swapper/5 prev_pid=0 prev_prio=120 prev_state=S ==> next_comm=cyclictest next_pid=2102 next_prio=19
2233 <...>-2102 [005] d..3 309.873625: sched_switch: prev_comm=cyclictest prev_pid=2102 prev_prio=19 prev_state=D ==> next_comm=swapper/5 next_pid=0 next_prio=120
2234 <idle>-0 [005] d.h3 309.874624: sched_waking: comm=cyclictest pid=2102 prio=19 target_cpu=005
2235 <idle>-0 [005] dNh4 309.874626: sched_wakeup: comm=cyclictest pid=2102 prio=19 target_cpu=005
2236 <idle>-0 [005] dNh3 309.874628: sched_waking: comm=cyclictest pid=2103 prio=19 target_cpu=005
2237 <idle>-0 [005] dNh4 309.874630: sched_wakeup: comm=cyclictest pid=2103 prio=19 target_cpu=005
2238 <idle>-0 [005] d..3 309.874633: sched_switch: prev_comm=swapper/5 prev_pid=0 prev_prio=120 prev_state=S ==> next_comm=cyclictest next_pid=2102 next_prio=19
2239 <idle>-0 [004] d.h3 309.874757: sched_waking: comm=gnome-terminal- pid=1699 prio=120 target_cpu=004
2240 <idle>-0 [004] dNh4 309.874762: sched_wakeup: comm=gnome-terminal- pid=1699 prio=120 target_cpu=004
2241 <idle>-0 [004] d..3 309.874766: sched_switch: prev_comm=swapper/4 prev_pid=0 prev_prio=120 prev_state=S ==> next_comm=gnome-terminal- next_pid=1699 next_prio=120
2242 gnome-terminal--1699 [004] d.h2 309.874941: sched_stat_runtime: comm=gnome-terminal- pid=1699 runtime=180706 [ns] vruntime=1126870572 [ns]
2243 <idle>-0 [003] d.s4 309.874956: sched_waking: comm=rcu_sched pid=9 prio=120 target_cpu=007
2244 <idle>-0 [003] d.s5 309.874960: sched_wake_idle_without_ipi: cpu=7
2245 <idle>-0 [003] d.s5 309.874961: sched_wakeup: comm=rcu_sched pid=9 prio=120 target_cpu=007
2246 <idle>-0 [007] d..3 309.874963: sched_switch: prev_comm=swapper/7 prev_pid=0 prev_prio=120 prev_state=S ==> next_comm=rcu_sched next_pid=9 next_prio=120
2247 rcu_sched-9 [007] d..3 309.874973: sched_stat_runtime: comm=rcu_sched pid=9 runtime=13646 [ns] vruntime=22531430286 [ns]
2248 rcu_sched-9 [007] d..3 309.874978: sched_switch: prev_comm=rcu_sched prev_pid=9 prev_prio=120 prev_state=R+ ==> next_comm=swapper/7 next_pid=0 next_prio=120
2249 <...>-2102 [005] d..4 309.874994: sched_migrate_task: comm=cyclictest pid=2103 prio=19 orig_cpu=5 dest_cpu=1
2250 <...>-2102 [005] d..4 309.875185: sched_wake_idle_without_ipi: cpu=1
2251 <idle>-0 [001] d..3 309.875200: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=S ==> next_comm=cyclictest next_pid=2103 next_prio=19
fd451a3d 2252
ff0d35e2
TZ
2253 - onchange(var).save(field,.. .)
2254
2255 The 'onchange(var).save(field,...)' hist trigger action is invoked
2256 whenever the value of 'var' associated with a histogram entry
2257 changes.
2258
2259 The end result is that the trace event fields specified as the
2260 onchange.save() params will be saved if 'var' changes for that
2261 hist trigger entry. This allows context from the event that
2262 changed the value to be saved for later reference. When the
2263 histogram is displayed, additional fields displaying the saved
2264 values will be printed.
2265
2266 - onchange(var).snapshot()
2267
2268 The 'onchange(var).snapshot()' hist trigger action is invoked
2269 whenever the value of 'var' associated with a histogram entry
2270 changes.
2271
2272 The end result is that a global snapshot of the trace buffer will
2273 be saved in the tracing/snapshot file if 'var' changes for any
2274 hist trigger entry.
2275
2276 Note that in this case the changed value is a global variable
fe4ec72c 2277 associated with current trace instance. The key of the specific
ff0d35e2
TZ
2278 trace event that caused the value to change and the global value
2279 itself are displayed, along with a message stating that a snapshot
2280 has been taken and where to find it. The user can use the key
2281 information displayed to locate the corresponding bucket in the
2282 histogram for even more detail.
2283
2284 As an example the below defines a hist trigger on the tcp_probe
2285 event, keyed on dport. Whenever a tcp_probe event occurs, the
2286 cwnd field is checked against the current value stored in the
2287 $cwnd variable. If the value has changed, a snapshot is taken.
2288 As part of the setup, all the scheduler and tcp events are also
2289 enabled, which are the events that will show up in the snapshot
2290 when it is taken at some point:
2291
2292 # echo 1 > /sys/kernel/debug/tracing/events/sched/enable
2293 # echo 1 > /sys/kernel/debug/tracing/events/tcp/enable
2294
2295 # echo 'hist:keys=dport:cwnd=snd_cwnd: \
2296 onchange($cwnd).save(snd_wnd,srtt,rcv_wnd): \
2297 onchange($cwnd).snapshot()' >> \
2298 /sys/kernel/debug/tracing/events/tcp/tcp_probe/trigger
2299
2300 When the histogram is displayed, for each bucket the tracked value
2301 and the saved values corresponding to that value are displayed
2302 following the rest of the fields.
2303
fe4ec72c 2304 If a snapshot was taken, there is also a message indicating that,
3df5ffd2
MCC
2305 along with the value and event that triggered the snapshot::
2306
2307 # cat /sys/kernel/debug/tracing/events/tcp/tcp_probe/hist
ff0d35e2 2308
ff0d35e2
TZ
2309 { dport: 1521 } hitcount: 8
2310 changed: 10 snd_wnd: 35456 srtt: 154262 rcv_wnd: 42112
2311
2312 { dport: 80 } hitcount: 23
2313 changed: 10 snd_wnd: 28960 srtt: 19604 rcv_wnd: 29312
2314
2315 { dport: 9001 } hitcount: 172
2316 changed: 10 snd_wnd: 48384 srtt: 260444 rcv_wnd: 55168
2317
2318 { dport: 443 } hitcount: 211
2319 changed: 10 snd_wnd: 26960 srtt: 17379 rcv_wnd: 28800
2320
3df5ffd2
MCC
2321 Snapshot taken (see tracing/snapshot). Details::
2322
ff0d35e2
TZ
2323 triggering value { onchange($cwnd) }: 10
2324 triggered by event with key: { dport: 80 }
2325
3df5ffd2
MCC
2326 Totals:
2327 Hits: 414
2328 Entries: 4
2329 Dropped: 0
ff0d35e2
TZ
2330
2331 In the above case, the event that triggered the snapshot has the
2332 key with dport == 80. If you look at the bucket that has 80 as
2333 the key, you'll find the additional values save()'d along with the
2334 changed value for that bucket, which should be the same as the
2335 global changed value (since that was the same value that triggered
2336 the global snapshot).
2337
2338 And finally, looking at the snapshot data should show at or near
3df5ffd2
MCC
2339 the end the event that triggered the snapshot::
2340
2341 # cat /sys/kernel/debug/tracing/snapshot
2342
2343 gnome-shell-1261 [006] dN.3 49.823113: sched_stat_runtime: comm=gnome-shell pid=1261 runtime=49347 [ns] vruntime=1835730389 [ns]
2344 kworker/u16:4-773 [003] d..3 49.823114: sched_switch: prev_comm=kworker/u16:4 prev_pid=773 prev_prio=120 prev_state=R+ ==> next_comm=kworker/3:2 next_pid=135 next_prio=120
2345 gnome-shell-1261 [006] d..3 49.823114: sched_switch: prev_comm=gnome-shell prev_pid=1261 prev_prio=120 prev_state=R+ ==> next_comm=kworker/6:2 next_pid=387 next_prio=120
2346 kworker/3:2-135 [003] d..3 49.823118: sched_stat_runtime: comm=kworker/3:2 pid=135 runtime=5339 [ns] vruntime=17815800388 [ns]
2347 kworker/6:2-387 [006] d..3 49.823120: sched_stat_runtime: comm=kworker/6:2 pid=387 runtime=9594 [ns] vruntime=14589605367 [ns]
2348 kworker/6:2-387 [006] d..3 49.823122: sched_switch: prev_comm=kworker/6:2 prev_pid=387 prev_prio=120 prev_state=R+ ==> next_comm=gnome-shell next_pid=1261 next_prio=120
2349 kworker/3:2-135 [003] d..3 49.823123: sched_switch: prev_comm=kworker/3:2 prev_pid=135 prev_prio=120 prev_state=T ==> next_comm=swapper/3 next_pid=0 next_prio=120
2350 <idle>-0 [004] ..s7 49.823798: tcp_probe: src=10.0.0.10:54326 dest=23.215.104.193:80 mark=0x0 length=32 snd_nxt=0xe3ae2ff5 snd_una=0xe3ae2ecd snd_cwnd=10 ssthresh=2147483647 snd_wnd=28960 srtt=19604 rcv_wnd=29312
ff0d35e2 2351
d3439f9d
SRV
23523. User space creating a trigger
2353--------------------------------
2354
2355Writing into /sys/kernel/tracing/trace_marker writes into the ftrace
2356ring buffer. This can also act like an event, by writing into the trigger
2357file located in /sys/kernel/tracing/events/ftrace/print/
2358
2359Modifying cyclictest to write into the trace_marker file before it sleeps
ea272257 2360and after it wakes up, something like this::
d3439f9d 2361
ea272257
MCC
2362 static void traceputs(char *str)
2363 {
d3439f9d
SRV
2364 /* tracemark_fd is the trace_marker file descriptor */
2365 if (tracemark_fd < 0)
2366 return;
2367 /* write the tracemark message */
2368 write(tracemark_fd, str, strlen(str));
ea272257 2369 }
d3439f9d 2370
ea272257 2371And later add something like::
d3439f9d
SRV
2372
2373 traceputs("start");
2374 clock_nanosleep(...);
2375 traceputs("end");
2376
ea272257 2377We can make a histogram from this::
d3439f9d
SRV
2378
2379 # cd /sys/kernel/tracing
2380 # echo 'latency u64 lat' > synthetic_events
2381 # echo 'hist:keys=common_pid:ts0=common_timestamp.usecs if buf == "start"' > events/ftrace/print/trigger
2382 # echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"' >> events/ftrace/print/trigger
2383 # echo 'hist:keys=lat,common_pid:sort=lat' > events/synthetic/latency/trigger
2384
2385The above created a synthetic event called "latency" and two histograms
2386against the trace_marker, one gets triggered when "start" is written into the
2387trace_marker file and the other when "end" is written. If the pids match, then
2388it will call the "latency" synthetic event with the calculated latency as its
2389parameter. Finally, a histogram is added to the latency synthetic event to
2390record the calculated latency along with the pid.
2391
ea272257 2392Now running cyclictest with::
d3439f9d
SRV
2393
2394 # ./cyclictest -p80 -d0 -i250 -n -a -t --tracemark -b 1000
2395
2396 -p80 : run threads at priority 80
2397 -d0 : have all threads run at the same interval
2398 -i250 : start the interval at 250 microseconds (all threads will do this)
2399 -n : sleep with nanosleep
2400 -a : affine all threads to a separate CPU
2401 -t : one thread per available CPU
2402 --tracemark : enable trace mark writing
2403 -b 1000 : stop if any latency is greater than 1000 microseconds
2404
2405Note, the -b 1000 is used just to make --tracemark available.
2406
ea272257 2407Then we can see the histogram created by this with::
d3439f9d
SRV
2408
2409 # cat events/synthetic/latency/hist
ea272257
MCC
2410 # event histogram
2411 #
2412 # trigger info: hist:keys=lat,common_pid:vals=hitcount:sort=lat:size=2048 [active]
2413 #
2414
2415 { lat: 107, common_pid: 2039 } hitcount: 1
2416 { lat: 122, common_pid: 2041 } hitcount: 1
2417 { lat: 166, common_pid: 2039 } hitcount: 1
2418 { lat: 174, common_pid: 2039 } hitcount: 1
2419 { lat: 194, common_pid: 2041 } hitcount: 1
2420 { lat: 196, common_pid: 2036 } hitcount: 1
2421 { lat: 197, common_pid: 2038 } hitcount: 1
2422 { lat: 198, common_pid: 2039 } hitcount: 1
2423 { lat: 199, common_pid: 2039 } hitcount: 1
2424 { lat: 200, common_pid: 2041 } hitcount: 1
2425 { lat: 201, common_pid: 2039 } hitcount: 2
2426 { lat: 202, common_pid: 2038 } hitcount: 1
2427 { lat: 202, common_pid: 2043 } hitcount: 1
2428 { lat: 203, common_pid: 2039 } hitcount: 1
2429 { lat: 203, common_pid: 2036 } hitcount: 1
2430 { lat: 203, common_pid: 2041 } hitcount: 1
2431 { lat: 206, common_pid: 2038 } hitcount: 2
2432 { lat: 207, common_pid: 2039 } hitcount: 1
2433 { lat: 207, common_pid: 2036 } hitcount: 1
2434 { lat: 208, common_pid: 2040 } hitcount: 1
2435 { lat: 209, common_pid: 2043 } hitcount: 1
2436 { lat: 210, common_pid: 2039 } hitcount: 1
2437 { lat: 211, common_pid: 2039 } hitcount: 4
2438 { lat: 212, common_pid: 2043 } hitcount: 1
2439 { lat: 212, common_pid: 2039 } hitcount: 2
2440 { lat: 213, common_pid: 2039 } hitcount: 1
2441 { lat: 214, common_pid: 2038 } hitcount: 1
2442 { lat: 214, common_pid: 2039 } hitcount: 2
2443 { lat: 214, common_pid: 2042 } hitcount: 1
2444 { lat: 215, common_pid: 2039 } hitcount: 1
2445 { lat: 217, common_pid: 2036 } hitcount: 1
2446 { lat: 217, common_pid: 2040 } hitcount: 1
2447 { lat: 217, common_pid: 2039 } hitcount: 1
2448 { lat: 218, common_pid: 2039 } hitcount: 6
2449 { lat: 219, common_pid: 2039 } hitcount: 9
2450 { lat: 220, common_pid: 2039 } hitcount: 11
2451 { lat: 221, common_pid: 2039 } hitcount: 5
2452 { lat: 221, common_pid: 2042 } hitcount: 1
2453 { lat: 222, common_pid: 2039 } hitcount: 7
2454 { lat: 223, common_pid: 2036 } hitcount: 1
2455 { lat: 223, common_pid: 2039 } hitcount: 3
2456 { lat: 224, common_pid: 2039 } hitcount: 4
2457 { lat: 224, common_pid: 2037 } hitcount: 1
2458 { lat: 224, common_pid: 2036 } hitcount: 2
2459 { lat: 225, common_pid: 2039 } hitcount: 5
2460 { lat: 225, common_pid: 2042 } hitcount: 1
2461 { lat: 226, common_pid: 2039 } hitcount: 7
2462 { lat: 226, common_pid: 2036 } hitcount: 4
2463 { lat: 227, common_pid: 2039 } hitcount: 6
2464 { lat: 227, common_pid: 2036 } hitcount: 12
2465 { lat: 227, common_pid: 2043 } hitcount: 1
2466 { lat: 228, common_pid: 2039 } hitcount: 7
2467 { lat: 228, common_pid: 2036 } hitcount: 14
2468 { lat: 229, common_pid: 2039 } hitcount: 9
2469 { lat: 229, common_pid: 2036 } hitcount: 8
2470 { lat: 229, common_pid: 2038 } hitcount: 1
2471 { lat: 230, common_pid: 2039 } hitcount: 11
2472 { lat: 230, common_pid: 2036 } hitcount: 6
2473 { lat: 230, common_pid: 2043 } hitcount: 1
2474 { lat: 230, common_pid: 2042 } hitcount: 2
2475 { lat: 231, common_pid: 2041 } hitcount: 1
2476 { lat: 231, common_pid: 2036 } hitcount: 6
2477 { lat: 231, common_pid: 2043 } hitcount: 1
2478 { lat: 231, common_pid: 2039 } hitcount: 8
2479 { lat: 232, common_pid: 2037 } hitcount: 1
2480 { lat: 232, common_pid: 2039 } hitcount: 6
2481 { lat: 232, common_pid: 2040 } hitcount: 2
2482 { lat: 232, common_pid: 2036 } hitcount: 5
2483 { lat: 232, common_pid: 2043 } hitcount: 1
2484 { lat: 233, common_pid: 2036 } hitcount: 5
2485 { lat: 233, common_pid: 2039 } hitcount: 11
2486 { lat: 234, common_pid: 2039 } hitcount: 4
2487 { lat: 234, common_pid: 2038 } hitcount: 2
2488 { lat: 234, common_pid: 2043 } hitcount: 2
2489 { lat: 234, common_pid: 2036 } hitcount: 11
2490 { lat: 234, common_pid: 2040 } hitcount: 1
2491 { lat: 235, common_pid: 2037 } hitcount: 2
2492 { lat: 235, common_pid: 2036 } hitcount: 8
2493 { lat: 235, common_pid: 2043 } hitcount: 2
2494 { lat: 235, common_pid: 2039 } hitcount: 5
2495 { lat: 235, common_pid: 2042 } hitcount: 2
2496 { lat: 235, common_pid: 2040 } hitcount: 4
2497 { lat: 235, common_pid: 2041 } hitcount: 1
2498 { lat: 236, common_pid: 2036 } hitcount: 7
2499 { lat: 236, common_pid: 2037 } hitcount: 1
2500 { lat: 236, common_pid: 2041 } hitcount: 5
2501 { lat: 236, common_pid: 2039 } hitcount: 3
2502 { lat: 236, common_pid: 2043 } hitcount: 9
2503 { lat: 236, common_pid: 2040 } hitcount: 7
2504 { lat: 237, common_pid: 2037 } hitcount: 1
2505 { lat: 237, common_pid: 2040 } hitcount: 1
2506 { lat: 237, common_pid: 2036 } hitcount: 9
2507 { lat: 237, common_pid: 2039 } hitcount: 3
2508 { lat: 237, common_pid: 2043 } hitcount: 8
2509 { lat: 237, common_pid: 2042 } hitcount: 2
2510 { lat: 237, common_pid: 2041 } hitcount: 2
2511 { lat: 238, common_pid: 2043 } hitcount: 10
2512 { lat: 238, common_pid: 2040 } hitcount: 1
2513 { lat: 238, common_pid: 2037 } hitcount: 9
2514 { lat: 238, common_pid: 2038 } hitcount: 1
2515 { lat: 238, common_pid: 2039 } hitcount: 1
2516 { lat: 238, common_pid: 2042 } hitcount: 3
2517 { lat: 238, common_pid: 2036 } hitcount: 7
2518 { lat: 239, common_pid: 2041 } hitcount: 1
2519 { lat: 239, common_pid: 2043 } hitcount: 11
2520 { lat: 239, common_pid: 2037 } hitcount: 11
2521 { lat: 239, common_pid: 2038 } hitcount: 6
2522 { lat: 239, common_pid: 2036 } hitcount: 7
2523 { lat: 239, common_pid: 2040 } hitcount: 1
2524 { lat: 239, common_pid: 2042 } hitcount: 9
2525 { lat: 240, common_pid: 2037 } hitcount: 29
2526 { lat: 240, common_pid: 2043 } hitcount: 15
2527 { lat: 240, common_pid: 2040 } hitcount: 44
2528 { lat: 240, common_pid: 2039 } hitcount: 1
2529 { lat: 240, common_pid: 2041 } hitcount: 2
2530 { lat: 240, common_pid: 2038 } hitcount: 1
2531 { lat: 240, common_pid: 2036 } hitcount: 10
2532 { lat: 240, common_pid: 2042 } hitcount: 13
2533 { lat: 241, common_pid: 2036 } hitcount: 21
2534 { lat: 241, common_pid: 2041 } hitcount: 36
2535 { lat: 241, common_pid: 2037 } hitcount: 34
2536 { lat: 241, common_pid: 2042 } hitcount: 14
2537 { lat: 241, common_pid: 2040 } hitcount: 94
2538 { lat: 241, common_pid: 2039 } hitcount: 12
2539 { lat: 241, common_pid: 2038 } hitcount: 2
2540 { lat: 241, common_pid: 2043 } hitcount: 28
2541 { lat: 242, common_pid: 2040 } hitcount: 109
2542 { lat: 242, common_pid: 2041 } hitcount: 506
2543 { lat: 242, common_pid: 2039 } hitcount: 155
2544 { lat: 242, common_pid: 2042 } hitcount: 21
2545 { lat: 242, common_pid: 2037 } hitcount: 52
2546 { lat: 242, common_pid: 2043 } hitcount: 21
2547 { lat: 242, common_pid: 2036 } hitcount: 16
2548 { lat: 242, common_pid: 2038 } hitcount: 156
2549 { lat: 243, common_pid: 2037 } hitcount: 46
2550 { lat: 243, common_pid: 2039 } hitcount: 40
2551 { lat: 243, common_pid: 2042 } hitcount: 119
2552 { lat: 243, common_pid: 2041 } hitcount: 611
2553 { lat: 243, common_pid: 2036 } hitcount: 69
2554 { lat: 243, common_pid: 2038 } hitcount: 784
2555 { lat: 243, common_pid: 2040 } hitcount: 323
2556 { lat: 243, common_pid: 2043 } hitcount: 14
2557 { lat: 244, common_pid: 2043 } hitcount: 35
2558 { lat: 244, common_pid: 2042 } hitcount: 305
2559 { lat: 244, common_pid: 2039 } hitcount: 8
2560 { lat: 244, common_pid: 2040 } hitcount: 4515
2561 { lat: 244, common_pid: 2038 } hitcount: 371
2562 { lat: 244, common_pid: 2037 } hitcount: 31
2563 { lat: 244, common_pid: 2036 } hitcount: 114
2564 { lat: 244, common_pid: 2041 } hitcount: 3396
2565 { lat: 245, common_pid: 2036 } hitcount: 700
2566 { lat: 245, common_pid: 2041 } hitcount: 2772
2567 { lat: 245, common_pid: 2037 } hitcount: 268
2568 { lat: 245, common_pid: 2039 } hitcount: 472
2569 { lat: 245, common_pid: 2038 } hitcount: 2758
2570 { lat: 245, common_pid: 2042 } hitcount: 3833
2571 { lat: 245, common_pid: 2040 } hitcount: 3105
2572 { lat: 245, common_pid: 2043 } hitcount: 645
2573 { lat: 246, common_pid: 2038 } hitcount: 3451
2574 { lat: 246, common_pid: 2041 } hitcount: 142
2575 { lat: 246, common_pid: 2037 } hitcount: 5101
2576 { lat: 246, common_pid: 2040 } hitcount: 68
2577 { lat: 246, common_pid: 2043 } hitcount: 5099
2578 { lat: 246, common_pid: 2039 } hitcount: 5608
2579 { lat: 246, common_pid: 2042 } hitcount: 3723
2580 { lat: 246, common_pid: 2036 } hitcount: 4738
2581 { lat: 247, common_pid: 2042 } hitcount: 312
2582 { lat: 247, common_pid: 2043 } hitcount: 2385
2583 { lat: 247, common_pid: 2041 } hitcount: 452
2584 { lat: 247, common_pid: 2038 } hitcount: 792
2585 { lat: 247, common_pid: 2040 } hitcount: 78
2586 { lat: 247, common_pid: 2036 } hitcount: 2375
2587 { lat: 247, common_pid: 2039 } hitcount: 1834
2588 { lat: 247, common_pid: 2037 } hitcount: 2655
2589 { lat: 248, common_pid: 2037 } hitcount: 36
2590 { lat: 248, common_pid: 2042 } hitcount: 11
2591 { lat: 248, common_pid: 2038 } hitcount: 122
2592 { lat: 248, common_pid: 2036 } hitcount: 135
2593 { lat: 248, common_pid: 2039 } hitcount: 26
2594 { lat: 248, common_pid: 2041 } hitcount: 503
2595 { lat: 248, common_pid: 2043 } hitcount: 66
2596 { lat: 248, common_pid: 2040 } hitcount: 46
2597 { lat: 249, common_pid: 2037 } hitcount: 29
2598 { lat: 249, common_pid: 2038 } hitcount: 1
2599 { lat: 249, common_pid: 2043 } hitcount: 29
2600 { lat: 249, common_pid: 2039 } hitcount: 8
2601 { lat: 249, common_pid: 2042 } hitcount: 56
2602 { lat: 249, common_pid: 2040 } hitcount: 27
2603 { lat: 249, common_pid: 2041 } hitcount: 11
2604 { lat: 249, common_pid: 2036 } hitcount: 27
2605 { lat: 250, common_pid: 2038 } hitcount: 1
2606 { lat: 250, common_pid: 2036 } hitcount: 30
2607 { lat: 250, common_pid: 2040 } hitcount: 19
2608 { lat: 250, common_pid: 2043 } hitcount: 22
2609 { lat: 250, common_pid: 2042 } hitcount: 20
2610 { lat: 250, common_pid: 2041 } hitcount: 1
2611 { lat: 250, common_pid: 2039 } hitcount: 6
2612 { lat: 250, common_pid: 2037 } hitcount: 48
2613 { lat: 251, common_pid: 2037 } hitcount: 43
2614 { lat: 251, common_pid: 2039 } hitcount: 1
2615 { lat: 251, common_pid: 2036 } hitcount: 12
2616 { lat: 251, common_pid: 2042 } hitcount: 2
2617 { lat: 251, common_pid: 2041 } hitcount: 1
2618 { lat: 251, common_pid: 2043 } hitcount: 15
2619 { lat: 251, common_pid: 2040 } hitcount: 3
2620 { lat: 252, common_pid: 2040 } hitcount: 1
2621 { lat: 252, common_pid: 2036 } hitcount: 12
2622 { lat: 252, common_pid: 2037 } hitcount: 21
2623 { lat: 252, common_pid: 2043 } hitcount: 14
2624 { lat: 253, common_pid: 2037 } hitcount: 21
2625 { lat: 253, common_pid: 2039 } hitcount: 2
2626 { lat: 253, common_pid: 2036 } hitcount: 9
2627 { lat: 253, common_pid: 2043 } hitcount: 6
2628 { lat: 253, common_pid: 2040 } hitcount: 1
2629 { lat: 254, common_pid: 2036 } hitcount: 8
2630 { lat: 254, common_pid: 2043 } hitcount: 3
2631 { lat: 254, common_pid: 2041 } hitcount: 1
2632 { lat: 254, common_pid: 2042 } hitcount: 1
2633 { lat: 254, common_pid: 2039 } hitcount: 1
2634 { lat: 254, common_pid: 2037 } hitcount: 12
2635 { lat: 255, common_pid: 2043 } hitcount: 1
2636 { lat: 255, common_pid: 2037 } hitcount: 2
2637 { lat: 255, common_pid: 2036 } hitcount: 2
2638 { lat: 255, common_pid: 2039 } hitcount: 8
2639 { lat: 256, common_pid: 2043 } hitcount: 1
2640 { lat: 256, common_pid: 2036 } hitcount: 4
2641 { lat: 256, common_pid: 2039 } hitcount: 6
2642 { lat: 257, common_pid: 2039 } hitcount: 5
2643 { lat: 257, common_pid: 2036 } hitcount: 4
2644 { lat: 258, common_pid: 2039 } hitcount: 5
2645 { lat: 258, common_pid: 2036 } hitcount: 2
2646 { lat: 259, common_pid: 2036 } hitcount: 7
2647 { lat: 259, common_pid: 2039 } hitcount: 7
2648 { lat: 260, common_pid: 2036 } hitcount: 8
2649 { lat: 260, common_pid: 2039 } hitcount: 6
2650 { lat: 261, common_pid: 2036 } hitcount: 5
2651 { lat: 261, common_pid: 2039 } hitcount: 7
2652 { lat: 262, common_pid: 2039 } hitcount: 5
2653 { lat: 262, common_pid: 2036 } hitcount: 5
2654 { lat: 263, common_pid: 2039 } hitcount: 7
2655 { lat: 263, common_pid: 2036 } hitcount: 7
2656 { lat: 264, common_pid: 2039 } hitcount: 9
2657 { lat: 264, common_pid: 2036 } hitcount: 9
2658 { lat: 265, common_pid: 2036 } hitcount: 5
2659 { lat: 265, common_pid: 2039 } hitcount: 1
2660 { lat: 266, common_pid: 2036 } hitcount: 1
2661 { lat: 266, common_pid: 2039 } hitcount: 3
2662 { lat: 267, common_pid: 2036 } hitcount: 1
2663 { lat: 267, common_pid: 2039 } hitcount: 3
2664 { lat: 268, common_pid: 2036 } hitcount: 1
2665 { lat: 268, common_pid: 2039 } hitcount: 6
2666 { lat: 269, common_pid: 2036 } hitcount: 1
2667 { lat: 269, common_pid: 2043 } hitcount: 1
2668 { lat: 269, common_pid: 2039 } hitcount: 2
2669 { lat: 270, common_pid: 2040 } hitcount: 1
2670 { lat: 270, common_pid: 2039 } hitcount: 6
2671 { lat: 271, common_pid: 2041 } hitcount: 1
2672 { lat: 271, common_pid: 2039 } hitcount: 5
2673 { lat: 272, common_pid: 2039 } hitcount: 10
2674 { lat: 273, common_pid: 2039 } hitcount: 8
2675 { lat: 274, common_pid: 2039 } hitcount: 2
2676 { lat: 275, common_pid: 2039 } hitcount: 1
2677 { lat: 276, common_pid: 2039 } hitcount: 2
2678 { lat: 276, common_pid: 2037 } hitcount: 1
2679 { lat: 276, common_pid: 2038 } hitcount: 1
2680 { lat: 277, common_pid: 2039 } hitcount: 1
2681 { lat: 277, common_pid: 2042 } hitcount: 1
2682 { lat: 278, common_pid: 2039 } hitcount: 1
2683 { lat: 279, common_pid: 2039 } hitcount: 4
2684 { lat: 279, common_pid: 2043 } hitcount: 1
2685 { lat: 280, common_pid: 2039 } hitcount: 3
2686 { lat: 283, common_pid: 2036 } hitcount: 2
2687 { lat: 284, common_pid: 2039 } hitcount: 1
2688 { lat: 284, common_pid: 2043 } hitcount: 1
2689 { lat: 288, common_pid: 2039 } hitcount: 1
2690 { lat: 289, common_pid: 2039 } hitcount: 1
2691 { lat: 300, common_pid: 2039 } hitcount: 1
2692 { lat: 384, common_pid: 2039 } hitcount: 1
2693
2694 Totals:
2695 Hits: 67625
2696 Entries: 278
2697 Dropped: 0
d3439f9d
SRV
2698
2699Note, the writes are around the sleep, so ideally they will all be of 250
2700microseconds. If you are wondering how there are several that are under
2701250 microseconds, that is because the way cyclictest works, is if one
2702iteration comes in late, the next one will set the timer to wake up less that
2703250. That is, if an iteration came in 50 microseconds late, the next wake up
2704will be at 200 microseconds.
2705
2706But this could easily be done in userspace. To make this even more
2707interesting, we can mix the histogram between events that happened in the
ea272257 2708kernel with trace_marker::
d3439f9d
SRV
2709
2710 # cd /sys/kernel/tracing
2711 # echo 'latency u64 lat' > synthetic_events
2712 # echo 'hist:keys=pid:ts0=common_timestamp.usecs' > events/sched/sched_waking/trigger
2713 # echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat) if buf == "end"' > events/ftrace/print/trigger
2714 # echo 'hist:keys=lat,common_pid:sort=lat' > events/synthetic/latency/trigger
2715
2716The difference this time is that instead of using the trace_marker to start
2717the latency, the sched_waking event is used, matching the common_pid for the
2718trace_marker write with the pid that is being woken by sched_waking.
2719
ea272257 2720After running cyclictest again with the same parameters, we now have::
d3439f9d
SRV
2721
2722 # cat events/synthetic/latency/hist
ea272257
MCC
2723 # event histogram
2724 #
2725 # trigger info: hist:keys=lat,common_pid:vals=hitcount:sort=lat:size=2048 [active]
2726 #
2727
2728 { lat: 7, common_pid: 2302 } hitcount: 640
2729 { lat: 7, common_pid: 2299 } hitcount: 42
2730 { lat: 7, common_pid: 2303 } hitcount: 18
2731 { lat: 7, common_pid: 2305 } hitcount: 166
2732 { lat: 7, common_pid: 2306 } hitcount: 1
2733 { lat: 7, common_pid: 2301 } hitcount: 91
2734 { lat: 7, common_pid: 2300 } hitcount: 17
2735 { lat: 8, common_pid: 2303 } hitcount: 8296
2736 { lat: 8, common_pid: 2304 } hitcount: 6864
2737 { lat: 8, common_pid: 2305 } hitcount: 9464
2738 { lat: 8, common_pid: 2301 } hitcount: 9213
2739 { lat: 8, common_pid: 2306 } hitcount: 6246
2740 { lat: 8, common_pid: 2302 } hitcount: 8797
2741 { lat: 8, common_pid: 2299 } hitcount: 8771
2742 { lat: 8, common_pid: 2300 } hitcount: 8119
2743 { lat: 9, common_pid: 2305 } hitcount: 1519
2744 { lat: 9, common_pid: 2299 } hitcount: 2346
2745 { lat: 9, common_pid: 2303 } hitcount: 2841
2746 { lat: 9, common_pid: 2301 } hitcount: 1846
2747 { lat: 9, common_pid: 2304 } hitcount: 3861
2748 { lat: 9, common_pid: 2302 } hitcount: 1210
2749 { lat: 9, common_pid: 2300 } hitcount: 2762
2750 { lat: 9, common_pid: 2306 } hitcount: 4247
2751 { lat: 10, common_pid: 2299 } hitcount: 16
2752 { lat: 10, common_pid: 2306 } hitcount: 333
2753 { lat: 10, common_pid: 2303 } hitcount: 16
2754 { lat: 10, common_pid: 2304 } hitcount: 168
2755 { lat: 10, common_pid: 2302 } hitcount: 240
2756 { lat: 10, common_pid: 2301 } hitcount: 28
2757 { lat: 10, common_pid: 2300 } hitcount: 95
2758 { lat: 10, common_pid: 2305 } hitcount: 18
2759 { lat: 11, common_pid: 2303 } hitcount: 5
2760 { lat: 11, common_pid: 2305 } hitcount: 8
2761 { lat: 11, common_pid: 2306 } hitcount: 221
2762 { lat: 11, common_pid: 2302 } hitcount: 76
2763 { lat: 11, common_pid: 2304 } hitcount: 26
2764 { lat: 11, common_pid: 2300 } hitcount: 125
2765 { lat: 11, common_pid: 2299 } hitcount: 2
2766 { lat: 12, common_pid: 2305 } hitcount: 3
2767 { lat: 12, common_pid: 2300 } hitcount: 6
2768 { lat: 12, common_pid: 2306 } hitcount: 90
2769 { lat: 12, common_pid: 2302 } hitcount: 4
2770 { lat: 12, common_pid: 2303 } hitcount: 1
2771 { lat: 12, common_pid: 2304 } hitcount: 122
2772 { lat: 13, common_pid: 2300 } hitcount: 12
2773 { lat: 13, common_pid: 2301 } hitcount: 1
2774 { lat: 13, common_pid: 2306 } hitcount: 32
2775 { lat: 13, common_pid: 2302 } hitcount: 5
2776 { lat: 13, common_pid: 2305 } hitcount: 1
2777 { lat: 13, common_pid: 2303 } hitcount: 1
2778 { lat: 13, common_pid: 2304 } hitcount: 61
2779 { lat: 14, common_pid: 2303 } hitcount: 4
2780 { lat: 14, common_pid: 2306 } hitcount: 5
2781 { lat: 14, common_pid: 2305 } hitcount: 4
2782 { lat: 14, common_pid: 2304 } hitcount: 62
2783 { lat: 14, common_pid: 2302 } hitcount: 19
2784 { lat: 14, common_pid: 2300 } hitcount: 33
2785 { lat: 14, common_pid: 2299 } hitcount: 1
2786 { lat: 14, common_pid: 2301 } hitcount: 4
2787 { lat: 15, common_pid: 2305 } hitcount: 1
2788 { lat: 15, common_pid: 2302 } hitcount: 25
2789 { lat: 15, common_pid: 2300 } hitcount: 11
2790 { lat: 15, common_pid: 2299 } hitcount: 5
2791 { lat: 15, common_pid: 2301 } hitcount: 1
2792 { lat: 15, common_pid: 2304 } hitcount: 8
2793 { lat: 15, common_pid: 2303 } hitcount: 1
2794 { lat: 15, common_pid: 2306 } hitcount: 6
2795 { lat: 16, common_pid: 2302 } hitcount: 31
2796 { lat: 16, common_pid: 2306 } hitcount: 3
2797 { lat: 16, common_pid: 2300 } hitcount: 5
2798 { lat: 17, common_pid: 2302 } hitcount: 6
2799 { lat: 17, common_pid: 2303 } hitcount: 1
2800 { lat: 18, common_pid: 2304 } hitcount: 1
2801 { lat: 18, common_pid: 2302 } hitcount: 8
2802 { lat: 18, common_pid: 2299 } hitcount: 1
2803 { lat: 18, common_pid: 2301 } hitcount: 1
2804 { lat: 19, common_pid: 2303 } hitcount: 4
2805 { lat: 19, common_pid: 2304 } hitcount: 5
2806 { lat: 19, common_pid: 2302 } hitcount: 4
2807 { lat: 19, common_pid: 2299 } hitcount: 3
2808 { lat: 19, common_pid: 2306 } hitcount: 1
2809 { lat: 19, common_pid: 2300 } hitcount: 4
2810 { lat: 19, common_pid: 2305 } hitcount: 5
2811 { lat: 20, common_pid: 2299 } hitcount: 2
2812 { lat: 20, common_pid: 2302 } hitcount: 3
2813 { lat: 20, common_pid: 2305 } hitcount: 1
2814 { lat: 20, common_pid: 2300 } hitcount: 2
2815 { lat: 20, common_pid: 2301 } hitcount: 2
2816 { lat: 20, common_pid: 2303 } hitcount: 3
2817 { lat: 21, common_pid: 2305 } hitcount: 1
2818 { lat: 21, common_pid: 2299 } hitcount: 5
2819 { lat: 21, common_pid: 2303 } hitcount: 4
2820 { lat: 21, common_pid: 2302 } hitcount: 7
2821 { lat: 21, common_pid: 2300 } hitcount: 1
2822 { lat: 21, common_pid: 2301 } hitcount: 5
2823 { lat: 21, common_pid: 2304 } hitcount: 2
2824 { lat: 22, common_pid: 2302 } hitcount: 5
2825 { lat: 22, common_pid: 2303 } hitcount: 1
2826 { lat: 22, common_pid: 2306 } hitcount: 3
2827 { lat: 22, common_pid: 2301 } hitcount: 2
2828 { lat: 22, common_pid: 2300 } hitcount: 1
2829 { lat: 22, common_pid: 2299 } hitcount: 1
2830 { lat: 22, common_pid: 2305 } hitcount: 1
2831 { lat: 22, common_pid: 2304 } hitcount: 1
2832 { lat: 23, common_pid: 2299 } hitcount: 1
2833 { lat: 23, common_pid: 2306 } hitcount: 2
2834 { lat: 23, common_pid: 2302 } hitcount: 6
2835 { lat: 24, common_pid: 2302 } hitcount: 3
2836 { lat: 24, common_pid: 2300 } hitcount: 1
2837 { lat: 24, common_pid: 2306 } hitcount: 2
2838 { lat: 24, common_pid: 2305 } hitcount: 1
2839 { lat: 24, common_pid: 2299 } hitcount: 1
2840 { lat: 25, common_pid: 2300 } hitcount: 1
2841 { lat: 25, common_pid: 2302 } hitcount: 4
2842 { lat: 26, common_pid: 2302 } hitcount: 2
2843 { lat: 27, common_pid: 2305 } hitcount: 1
2844 { lat: 27, common_pid: 2300 } hitcount: 1
2845 { lat: 27, common_pid: 2302 } hitcount: 3
2846 { lat: 28, common_pid: 2306 } hitcount: 1
2847 { lat: 28, common_pid: 2302 } hitcount: 4
2848 { lat: 29, common_pid: 2302 } hitcount: 1
2849 { lat: 29, common_pid: 2300 } hitcount: 2
2850 { lat: 29, common_pid: 2306 } hitcount: 1
2851 { lat: 29, common_pid: 2304 } hitcount: 1
2852 { lat: 30, common_pid: 2302 } hitcount: 4
2853 { lat: 31, common_pid: 2302 } hitcount: 6
2854 { lat: 32, common_pid: 2302 } hitcount: 1
2855 { lat: 33, common_pid: 2299 } hitcount: 1
2856 { lat: 33, common_pid: 2302 } hitcount: 3
2857 { lat: 34, common_pid: 2302 } hitcount: 2
2858 { lat: 35, common_pid: 2302 } hitcount: 1
2859 { lat: 35, common_pid: 2304 } hitcount: 1
2860 { lat: 36, common_pid: 2302 } hitcount: 4
2861 { lat: 37, common_pid: 2302 } hitcount: 6
2862 { lat: 38, common_pid: 2302 } hitcount: 2
2863 { lat: 39, common_pid: 2302 } hitcount: 2
2864 { lat: 39, common_pid: 2304 } hitcount: 1
2865 { lat: 40, common_pid: 2304 } hitcount: 2
2866 { lat: 40, common_pid: 2302 } hitcount: 5
2867 { lat: 41, common_pid: 2304 } hitcount: 1
2868 { lat: 41, common_pid: 2302 } hitcount: 8
2869 { lat: 42, common_pid: 2302 } hitcount: 6
2870 { lat: 42, common_pid: 2304 } hitcount: 1
2871 { lat: 43, common_pid: 2302 } hitcount: 3
2872 { lat: 43, common_pid: 2304 } hitcount: 4
2873 { lat: 44, common_pid: 2302 } hitcount: 6
2874 { lat: 45, common_pid: 2302 } hitcount: 5
2875 { lat: 46, common_pid: 2302 } hitcount: 5
2876 { lat: 47, common_pid: 2302 } hitcount: 7
2877 { lat: 48, common_pid: 2301 } hitcount: 1
2878 { lat: 48, common_pid: 2302 } hitcount: 9
2879 { lat: 49, common_pid: 2302 } hitcount: 3
2880 { lat: 50, common_pid: 2302 } hitcount: 1
2881 { lat: 50, common_pid: 2301 } hitcount: 1
2882 { lat: 51, common_pid: 2302 } hitcount: 2
2883 { lat: 51, common_pid: 2301 } hitcount: 1
2884 { lat: 61, common_pid: 2302 } hitcount: 1
2885 { lat: 110, common_pid: 2302 } hitcount: 1
2886
2887 Totals:
2888 Hits: 89565
2889 Entries: 158
2890 Dropped: 0
d3439f9d
SRV
2891
2892This doesn't tell us any information about how late cyclictest may have
2893woken up, but it does show us a nice histogram of how long it took from
2894the time that cyclictest was woken to the time it made it into user space.