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