brintos

brintos / linux-shallow public Read only

0
0
Text · 159.7 KiB · 3c9b263 Raw
3072 lines · plain
1================2Event Histograms3================4 5Documentation written by Tom Zanussi6 71. Introduction8===============9 10  Histogram triggers are special event triggers that can be used to11  aggregate trace event data into histograms.  For information on12  trace events and event triggers, see Documentation/trace/events.rst.13 14 152. Histogram Trigger Command16============================17 18  A histogram trigger command is an event trigger command that19  aggregates event hits into a hash table keyed on one or more trace20  event format fields (or stacktrace) and a set of running totals21  derived from one or more trace event format fields and/or event22  counts (hitcount).23 24  The format of a hist trigger is as follows::25 26        hist:keys=<field1[,field2,...]>[:values=<field1[,field2,...]>]27          [:sort=<field1[,field2,...]>][:size=#entries][:pause][:continue]28          [:clear][:name=histname1][:nohitcount][:<handler>.<action>] [if <filter>]29 30  When a matching event is hit, an entry is added to a hash table31  using the key(s) and value(s) named.  Keys and values correspond to32  fields in the event's format description.  Values must correspond to33  numeric fields - on an event hit, the value(s) will be added to a34  sum kept for that field.  The special string 'hitcount' can be used35  in place of an explicit value field - this is simply a count of36  event hits.  If 'values' isn't specified, an implicit 'hitcount'37  value will be automatically created and used as the only value.38  Keys can be any field, or the special string 'common_stacktrace', which39  will use the event's kernel stacktrace as the key.  The keywords40  'keys' or 'key' can be used to specify keys, and the keywords41  'values', 'vals', or 'val' can be used to specify values.  Compound42  keys consisting of up to three fields can be specified by the 'keys'43  keyword.  Hashing a compound key produces a unique entry in the44  table for each unique combination of component keys, and can be45  useful for providing more fine-grained summaries of event data.46  Additionally, sort keys consisting of up to two fields can be47  specified by the 'sort' keyword.  If more than one field is48  specified, the result will be a 'sort within a sort': the first key49  is taken to be the primary sort key and the second the secondary50  key.  If a hist trigger is given a name using the 'name' parameter,51  its histogram data will be shared with other triggers of the same52  name, and trigger hits will update this common data.  Only triggers53  with 'compatible' fields can be combined in this way; triggers are54  'compatible' if the fields named in the trigger share the same55  number and type of fields and those fields also have the same names.56  Note that any two events always share the compatible 'hitcount' and57  'common_stacktrace' fields and can therefore be combined using those58  fields, however pointless that may be.59 60  'hist' triggers add a 'hist' file to each event's subdirectory.61  Reading the 'hist' file for the event will dump the hash table in62  its entirety to stdout.  If there are multiple hist triggers63  attached to an event, there will be a table for each trigger in the64  output.  The table displayed for a named trigger will be the same as65  any other instance having the same name. Each printed hash table66  entry is a simple list of the keys and values comprising the entry;67  keys are printed first and are delineated by curly braces, and are68  followed by the set of value fields for the entry.  By default,69  numeric fields are displayed as base-10 integers.  This can be70  modified by appending any of the following modifiers to the field71  name:72 73	=============  =================================================74        .hex           display a number as a hex value75	.sym           display an address as a symbol76	.sym-offset    display an address as a symbol and offset77	.syscall       display a syscall id as a system call name78	.execname      display a common_pid as a program name79	.log2          display log2 value rather than raw number80	.buckets=size  display grouping of values rather than raw number81	.usecs         display a common_timestamp in microseconds82        .percent       display a number of percentage value83        .graph         display a bar-graph of a value84	.stacktrace    display as a stacktrace (must by a long[] type)85	=============  =================================================86 87  Note that in general the semantics of a given field aren't88  interpreted when applying a modifier to it, but there are some89  restrictions to be aware of in this regard:90 91    - only the 'hex' modifier can be used for values (because values92      are essentially sums, and the other modifiers don't make sense93      in that context).94    - the 'execname' modifier can only be used on a 'common_pid'.  The95      reason for this is that the execname is simply the 'comm' value96      saved for the 'current' process when an event was triggered,97      which is the same as the common_pid value saved by the event98      tracing code.  Trying to apply that comm value to other pid99      values wouldn't be correct, and typically events that care save100      pid-specific comm fields in the event itself.101 102  A typical usage scenario would be the following to enable a hist103  trigger, read its current contents, and then turn it off::104 105    # echo 'hist:keys=skbaddr.hex:vals=len' > \106      /sys/kernel/tracing/events/net/netif_rx/trigger107 108    # cat /sys/kernel/tracing/events/net/netif_rx/hist109 110    # echo '!hist:keys=skbaddr.hex:vals=len' > \111      /sys/kernel/tracing/events/net/netif_rx/trigger112 113  The trigger file itself can be read to show the details of the114  currently attached hist trigger.  This information is also displayed115  at the top of the 'hist' file when read.116 117  By default, the size of the hash table is 2048 entries.  The 'size'118  parameter can be used to specify more or fewer than that.  The units119  are in terms of hashtable entries - if a run uses more entries than120  specified, the results will show the number of 'drops', the number121  of hits that were ignored.  The size should be a power of 2 between122  128 and 131072 (any non- power-of-2 number specified will be rounded123  up).124 125  The 'sort' parameter can be used to specify a value field to sort126  on.  The default if unspecified is 'hitcount' and the default sort127  order is 'ascending'.  To sort in the opposite direction, append128  .descending' to the sort key.129 130  The 'pause' parameter can be used to pause an existing hist trigger131  or to start a hist trigger but not log any events until told to do132  so.  'continue' or 'cont' can be used to start or restart a paused133  hist trigger.134 135  The 'clear' parameter will clear the contents of a running hist136  trigger and leave its current paused/active state.137 138  Note that the 'pause', 'cont', and 'clear' parameters should be139  applied using 'append' shell operator ('>>') if applied to an140  existing trigger, rather than via the '>' operator, which will cause141  the trigger to be removed through truncation.142 143  The 'nohitcount' (or NOHC) parameter will suppress display of144  raw hitcount in the histogram. This option requires at least one145  value field which is not a 'raw hitcount'. For example,146  'hist:...:vals=hitcount:nohitcount' is rejected, but147  'hist:...:vals=hitcount.percent:nohitcount' is OK.148 149- enable_hist/disable_hist150 151  The enable_hist and disable_hist triggers can be used to have one152  event conditionally start and stop another event's already-attached153  hist trigger.  Any number of enable_hist and disable_hist triggers154  can be attached to a given event, allowing that event to kick off155  and stop aggregations on a host of other events.156 157  The format is very similar to the enable/disable_event triggers::158 159      enable_hist:<system>:<event>[:count]160      disable_hist:<system>:<event>[:count]161 162  Instead of enabling or disabling the tracing of the target event163  into the trace buffer as the enable/disable_event triggers do, the164  enable/disable_hist triggers enable or disable the aggregation of165  the target event into a hash table.166 167  A typical usage scenario for the enable_hist/disable_hist triggers168  would be to first set up a paused hist trigger on some event,169  followed by an enable_hist/disable_hist pair that turns the hist170  aggregation on and off when conditions of interest are hit::171 172   # echo 'hist:keys=skbaddr.hex:vals=len:pause' > \173      /sys/kernel/tracing/events/net/netif_receive_skb/trigger174 175    # echo 'enable_hist:net:netif_receive_skb if filename==/usr/bin/wget' > \176      /sys/kernel/tracing/events/sched/sched_process_exec/trigger177 178    # echo 'disable_hist:net:netif_receive_skb if comm==wget' > \179      /sys/kernel/tracing/events/sched/sched_process_exit/trigger180 181  The above sets up an initially paused hist trigger which is unpaused182  and starts aggregating events when a given program is executed, and183  which stops aggregating when the process exits and the hist trigger184  is paused again.185 186  The examples below provide a more concrete illustration of the187  concepts and typical usage patterns discussed above.188 189'special' event fields190------------------------191 192  There are a number of 'special event fields' available for use as193  keys or values in a hist trigger.  These look like and behave as if194  they were actual event fields, but aren't really part of the event's195  field definition or format file.  They are however available for any196  event, and can be used anywhere an actual event field could be.197  They are:198 199    ====================== ==== =======================================200    common_timestamp       u64  timestamp (from ring buffer) associated201                                with the event, in nanoseconds.  May be202			        modified by .usecs to have timestamps203			        interpreted as microseconds.204    common_cpu             int  the cpu on which the event occurred.205    ====================== ==== =======================================206 207Extended error information208--------------------------209 210  For some error conditions encountered when invoking a hist trigger211  command, extended error information is available via the212  tracing/error_log file.  See Error Conditions in213  :file:`Documentation/trace/ftrace.rst` for details.214 2156.2 'hist' trigger examples216---------------------------217 218  The first set of examples creates aggregations using the kmalloc219  event.  The fields that can be used for the hist trigger are listed220  in the kmalloc event's format file::221 222    # cat /sys/kernel/tracing/events/kmem/kmalloc/format223    name: kmalloc224    ID: 374225    format:226	field:unsigned short common_type;	offset:0;	size:2;	signed:0;227	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;228	field:unsigned char common_preempt_count;		offset:3;	size:1;	signed:0;229	field:int common_pid;					offset:4;	size:4;	signed:1;230 231	field:unsigned long call_site;				offset:8;	size:8;	signed:0;232	field:const void * ptr;					offset:16;	size:8;	signed:0;233	field:size_t bytes_req;					offset:24;	size:8;	signed:0;234	field:size_t bytes_alloc;				offset:32;	size:8;	signed:0;235	field:gfp_t gfp_flags;					offset:40;	size:4;	signed:0;236 237  We'll start by creating a hist trigger that generates a simple table238  that lists the total number of bytes requested for each function in239  the kernel that made one or more calls to kmalloc::240 241    # echo 'hist:key=call_site:val=bytes_req.buckets=32' > \242            /sys/kernel/tracing/events/kmem/kmalloc/trigger243 244  This tells the tracing system to create a 'hist' trigger using the245  call_site field of the kmalloc event as the key for the table, which246  just means that each unique call_site address will have an entry247  created for it in the table.  The 'val=bytes_req' parameter tells248  the hist trigger that for each unique entry (call_site) in the249  table, it should keep a running total of the number of bytes250  requested by that call_site.251 252  We'll let it run for awhile and then dump the contents of the 'hist'253  file in the kmalloc event's subdirectory (for readability, a number254  of entries have been omitted)::255 256    # cat /sys/kernel/tracing/events/kmem/kmalloc/hist257    # trigger info: hist:keys=call_site:vals=bytes_req:sort=hitcount:size=2048 [active]258 259    { call_site: 18446744072106379007 } hitcount:          1  bytes_req:        176260    { call_site: 18446744071579557049 } hitcount:          1  bytes_req:       1024261    { call_site: 18446744071580608289 } hitcount:          1  bytes_req:      16384262    { call_site: 18446744071581827654 } hitcount:          1  bytes_req:         24263    { call_site: 18446744071580700980 } hitcount:          1  bytes_req:          8264    { call_site: 18446744071579359876 } hitcount:          1  bytes_req:        152265    { call_site: 18446744071580795365 } hitcount:          3  bytes_req:        144266    { call_site: 18446744071581303129 } hitcount:          3  bytes_req:        144267    { call_site: 18446744071580713234 } hitcount:          4  bytes_req:       2560268    { call_site: 18446744071580933750 } hitcount:          4  bytes_req:        736269    .270    .271    .272    { call_site: 18446744072106047046 } hitcount:         69  bytes_req:       5576273    { call_site: 18446744071582116407 } hitcount:         73  bytes_req:       2336274    { call_site: 18446744072106054684 } hitcount:        136  bytes_req:     140504275    { call_site: 18446744072106224230 } hitcount:        136  bytes_req:      19584276    { call_site: 18446744072106078074 } hitcount:        153  bytes_req:       2448277    { call_site: 18446744072106062406 } hitcount:        153  bytes_req:      36720278    { call_site: 18446744071582507929 } hitcount:        153  bytes_req:      37088279    { call_site: 18446744072102520590 } hitcount:        273  bytes_req:      10920280    { call_site: 18446744071582143559 } hitcount:        358  bytes_req:        716281    { call_site: 18446744072106465852 } hitcount:        417  bytes_req:      56712282    { call_site: 18446744072102523378 } hitcount:        485  bytes_req:      27160283    { call_site: 18446744072099568646 } hitcount:       1676  bytes_req:      33520284 285    Totals:286        Hits: 4610287        Entries: 45288        Dropped: 0289 290  The output displays a line for each entry, beginning with the key291  specified in the trigger, followed by the value(s) also specified in292  the trigger.  At the beginning of the output is a line that displays293  the trigger info, which can also be displayed by reading the294  'trigger' file::295 296    # cat /sys/kernel/tracing/events/kmem/kmalloc/trigger297    hist:keys=call_site:vals=bytes_req:sort=hitcount:size=2048 [active]298 299  At the end of the output are a few lines that display the overall300  totals for the run.  The 'Hits' field shows the total number of301  times the event trigger was hit, the 'Entries' field shows the total302  number of used entries in the hash table, and the 'Dropped' field303  shows the number of hits that were dropped because the number of304  used entries for the run exceeded the maximum number of entries305  allowed for the table (normally 0, but if not a hint that you may306  want to increase the size of the table using the 'size' parameter).307 308  Notice in the above output that there's an extra field, 'hitcount',309  which wasn't specified in the trigger.  Also notice that in the310  trigger info output, there's a parameter, 'sort=hitcount', which311  wasn't specified in the trigger either.  The reason for that is that312  every trigger implicitly keeps a count of the total number of hits313  attributed to a given entry, called the 'hitcount'.  That hitcount314  information is explicitly displayed in the output, and in the315  absence of a user-specified sort parameter, is used as the default316  sort field.317 318  The value 'hitcount' can be used in place of an explicit value in319  the 'values' parameter if you don't really need to have any320  particular field summed and are mainly interested in hit321  frequencies.322 323  To turn the hist trigger off, simply call up the trigger in the324  command history and re-execute it with a '!' prepended::325 326    # echo '!hist:key=call_site:val=bytes_req' > \327           /sys/kernel/tracing/events/kmem/kmalloc/trigger328 329  Finally, notice that the call_site as displayed in the output above330  isn't really very useful.  It's an address, but normally addresses331  are displayed in hex.  To have a numeric field displayed as a hex332  value, simply append '.hex' to the field name in the trigger::333 334    # echo 'hist:key=call_site.hex:val=bytes_req' > \335           /sys/kernel/tracing/events/kmem/kmalloc/trigger336 337    # cat /sys/kernel/tracing/events/kmem/kmalloc/hist338    # trigger info: hist:keys=call_site.hex:vals=bytes_req:sort=hitcount:size=2048 [active]339 340    { call_site: ffffffffa026b291 } hitcount:          1  bytes_req:        433341    { call_site: ffffffffa07186ff } hitcount:          1  bytes_req:        176342    { call_site: ffffffff811ae721 } hitcount:          1  bytes_req:      16384343    { call_site: ffffffff811c5134 } hitcount:          1  bytes_req:          8344    { call_site: ffffffffa04a9ebb } hitcount:          1  bytes_req:        511345    { call_site: ffffffff8122e0a6 } hitcount:          1  bytes_req:         12346    { call_site: ffffffff8107da84 } hitcount:          1  bytes_req:        152347    { call_site: ffffffff812d8246 } hitcount:          1  bytes_req:         24348    { call_site: ffffffff811dc1e5 } hitcount:          3  bytes_req:        144349    { call_site: ffffffffa02515e8 } hitcount:          3  bytes_req:        648350    { call_site: ffffffff81258159 } hitcount:          3  bytes_req:        144351    { call_site: ffffffff811c80f4 } hitcount:          4  bytes_req:        544352    .353    .354    .355    { call_site: ffffffffa06c7646 } hitcount:        106  bytes_req:       8024356    { call_site: ffffffffa06cb246 } hitcount:        132  bytes_req:      31680357    { call_site: ffffffffa06cef7a } hitcount:        132  bytes_req:       2112358    { call_site: ffffffff8137e399 } hitcount:        132  bytes_req:      23232359    { call_site: ffffffffa06c941c } hitcount:        185  bytes_req:     171360360    { call_site: ffffffffa06f2a66 } hitcount:        185  bytes_req:      26640361    { call_site: ffffffffa036a70e } hitcount:        265  bytes_req:      10600362    { call_site: ffffffff81325447 } hitcount:        292  bytes_req:        584363    { call_site: ffffffffa072da3c } hitcount:        446  bytes_req:      60656364    { call_site: ffffffffa036b1f2 } hitcount:        526  bytes_req:      29456365    { call_site: ffffffffa0099c06 } hitcount:       1780  bytes_req:      35600366 367    Totals:368        Hits: 4775369        Entries: 46370        Dropped: 0371 372  Even that's only marginally more useful - while hex values do look373  more like addresses, what users are typically more interested in374  when looking at text addresses are the corresponding symbols375  instead.  To have an address displayed as symbolic value instead,376  simply append '.sym' or '.sym-offset' to the field name in the377  trigger::378 379    # echo 'hist:key=call_site.sym:val=bytes_req' > \380           /sys/kernel/tracing/events/kmem/kmalloc/trigger381 382    # cat /sys/kernel/tracing/events/kmem/kmalloc/hist383    # trigger info: hist:keys=call_site.sym:vals=bytes_req:sort=hitcount:size=2048 [active]384 385    { call_site: [ffffffff810adcb9] syslog_print_all                              } hitcount:          1  bytes_req:       1024386    { call_site: [ffffffff8154bc62] usb_control_msg                               } hitcount:          1  bytes_req:          8387    { call_site: [ffffffffa00bf6fe] hidraw_send_report [hid]                      } hitcount:          1  bytes_req:          7388    { call_site: [ffffffff8154acbe] usb_alloc_urb                                 } hitcount:          1  bytes_req:        192389    { call_site: [ffffffffa00bf1ca] hidraw_report_event [hid]                     } hitcount:          1  bytes_req:          7390    { call_site: [ffffffff811e3a25] __seq_open_private                            } hitcount:          1  bytes_req:         40391    { call_site: [ffffffff8109524a] alloc_fair_sched_group                        } hitcount:          2  bytes_req:        128392    { call_site: [ffffffff811febd5] fsnotify_alloc_group                          } hitcount:          2  bytes_req:        528393    { call_site: [ffffffff81440f58] __tty_buffer_request_room                     } hitcount:          2  bytes_req:       2624394    { call_site: [ffffffff81200ba6] inotify_new_group                             } hitcount:          2  bytes_req:         96395    { call_site: [ffffffffa05e19af] ieee80211_start_tx_ba_session [mac80211]      } hitcount:          2  bytes_req:        464396    { call_site: [ffffffff81672406] tcp_get_metrics                               } hitcount:          2  bytes_req:        304397    { call_site: [ffffffff81097ec2] alloc_rt_sched_group                          } hitcount:          2  bytes_req:        128398    { call_site: [ffffffff81089b05] sched_create_group                            } hitcount:          2  bytes_req:       1424399    .400    .401    .402    { call_site: [ffffffffa04a580c] intel_crtc_page_flip [i915]                   } hitcount:       1185  bytes_req:     123240403    { call_site: [ffffffffa0287592] drm_mode_page_flip_ioctl [drm]                } hitcount:       1185  bytes_req:     104280404    { call_site: [ffffffffa04c4a3c] intel_plane_duplicate_state [i915]            } hitcount:       1402  bytes_req:     190672405    { call_site: [ffffffff812891ca] ext4_find_extent                              } hitcount:       1518  bytes_req:     146208406    { call_site: [ffffffffa029070e] drm_vma_node_allow [drm]                      } hitcount:       1746  bytes_req:      69840407    { call_site: [ffffffffa045e7c4] i915_gem_do_execbuffer.isra.23 [i915]         } hitcount:       2021  bytes_req:     792312408    { call_site: [ffffffffa02911f2] drm_modeset_lock_crtc [drm]                   } hitcount:       2592  bytes_req:     145152409    { call_site: [ffffffffa0489a66] intel_ring_begin [i915]                       } hitcount:       2629  bytes_req:     378576410    { call_site: [ffffffffa046041c] i915_gem_execbuffer2 [i915]                   } hitcount:       2629  bytes_req:    3783248411    { call_site: [ffffffff81325607] apparmor_file_alloc_security                  } hitcount:       5192  bytes_req:      10384412    { call_site: [ffffffffa00b7c06] hid_report_raw_event [hid]                    } hitcount:       5529  bytes_req:     110584413    { call_site: [ffffffff8131ebf7] aa_alloc_task_context                         } hitcount:      21943  bytes_req:     702176414    { call_site: [ffffffff8125847d] ext4_htree_store_dirent                       } hitcount:      55759  bytes_req:    5074265415 416    Totals:417        Hits: 109928418        Entries: 71419        Dropped: 0420 421  Because the default sort key above is 'hitcount', the above shows a422  the list of call_sites by increasing hitcount, so that at the bottom423  we see the functions that made the most kmalloc calls during the424  run.  If instead we wanted to see the top kmalloc callers in425  terms of the number of bytes requested rather than the number of426  calls, and we wanted the top caller to appear at the top, we can use427  the 'sort' parameter, along with the 'descending' modifier::428 429    # echo 'hist:key=call_site.sym:val=bytes_req:sort=bytes_req.descending' > \430           /sys/kernel/tracing/events/kmem/kmalloc/trigger431 432    # cat /sys/kernel/tracing/events/kmem/kmalloc/hist433    # trigger info: hist:keys=call_site.sym:vals=bytes_req:sort=bytes_req.descending:size=2048 [active]434 435    { call_site: [ffffffffa046041c] i915_gem_execbuffer2 [i915]                   } hitcount:       2186  bytes_req:    3397464436    { call_site: [ffffffffa045e7c4] i915_gem_do_execbuffer.isra.23 [i915]         } hitcount:       1790  bytes_req:     712176437    { call_site: [ffffffff8125847d] ext4_htree_store_dirent                       } hitcount:       8132  bytes_req:     513135438    { call_site: [ffffffff811e2a1b] seq_buf_alloc                                 } hitcount:        106  bytes_req:     440128439    { call_site: [ffffffffa0489a66] intel_ring_begin [i915]                       } hitcount:       2186  bytes_req:     314784440    { call_site: [ffffffff812891ca] ext4_find_extent                              } hitcount:       2174  bytes_req:     208992441    { call_site: [ffffffff811ae8e1] __kmalloc                                     } hitcount:          8  bytes_req:     131072442    { call_site: [ffffffffa04c4a3c] intel_plane_duplicate_state [i915]            } hitcount:        859  bytes_req:     116824443    { call_site: [ffffffffa02911f2] drm_modeset_lock_crtc [drm]                   } hitcount:       1834  bytes_req:     102704444    { call_site: [ffffffffa04a580c] intel_crtc_page_flip [i915]                   } hitcount:        972  bytes_req:     101088445    { call_site: [ffffffffa0287592] drm_mode_page_flip_ioctl [drm]                } hitcount:        972  bytes_req:      85536446    { call_site: [ffffffffa00b7c06] hid_report_raw_event [hid]                    } hitcount:       3333  bytes_req:      66664447    { call_site: [ffffffff8137e559] sg_kmalloc                                    } hitcount:        209  bytes_req:      61632448    .449    .450    .451    { call_site: [ffffffff81095225] alloc_fair_sched_group                        } hitcount:          2  bytes_req:        128452    { call_site: [ffffffff81097ec2] alloc_rt_sched_group                          } hitcount:          2  bytes_req:        128453    { call_site: [ffffffff812d8406] copy_semundo                                  } hitcount:          2  bytes_req:         48454    { call_site: [ffffffff81200ba6] inotify_new_group                             } hitcount:          1  bytes_req:         48455    { call_site: [ffffffffa027121a] drm_getmagic [drm]                            } hitcount:          1  bytes_req:         48456    { call_site: [ffffffff811e3a25] __seq_open_private                            } hitcount:          1  bytes_req:         40457    { call_site: [ffffffff811c52f4] bprm_change_interp                            } hitcount:          2  bytes_req:         16458    { call_site: [ffffffff8154bc62] usb_control_msg                               } hitcount:          1  bytes_req:          8459    { call_site: [ffffffffa00bf1ca] hidraw_report_event [hid]                     } hitcount:          1  bytes_req:          7460    { call_site: [ffffffffa00bf6fe] hidraw_send_report [hid]                      } hitcount:          1  bytes_req:          7461 462    Totals:463        Hits: 32133464        Entries: 81465        Dropped: 0466 467  To display the offset and size information in addition to the symbol468  name, just use 'sym-offset' instead::469 470    # echo 'hist:key=call_site.sym-offset:val=bytes_req:sort=bytes_req.descending' > \471           /sys/kernel/tracing/events/kmem/kmalloc/trigger472 473    # cat /sys/kernel/tracing/events/kmem/kmalloc/hist474    # trigger info: hist:keys=call_site.sym-offset:vals=bytes_req:sort=bytes_req.descending:size=2048 [active]475 476    { call_site: [ffffffffa046041c] i915_gem_execbuffer2+0x6c/0x2c0 [i915]                  } hitcount:       4569  bytes_req:    3163720477    { call_site: [ffffffffa0489a66] intel_ring_begin+0xc6/0x1f0 [i915]                      } hitcount:       4569  bytes_req:     657936478    { call_site: [ffffffffa045e7c4] i915_gem_do_execbuffer.isra.23+0x694/0x1020 [i915]      } hitcount:       1519  bytes_req:     472936479    { call_site: [ffffffffa045e646] i915_gem_do_execbuffer.isra.23+0x516/0x1020 [i915]      } hitcount:       3050  bytes_req:     211832480    { call_site: [ffffffff811e2a1b] seq_buf_alloc+0x1b/0x50                                 } hitcount:         34  bytes_req:     148384481    { call_site: [ffffffffa04a580c] intel_crtc_page_flip+0xbc/0x870 [i915]                  } hitcount:       1385  bytes_req:     144040482    { call_site: [ffffffff811ae8e1] __kmalloc+0x191/0x1b0                                   } hitcount:          8  bytes_req:     131072483    { call_site: [ffffffffa0287592] drm_mode_page_flip_ioctl+0x282/0x360 [drm]              } hitcount:       1385  bytes_req:     121880484    { call_site: [ffffffffa02911f2] drm_modeset_lock_crtc+0x32/0x100 [drm]                  } hitcount:       1848  bytes_req:     103488485    { call_site: [ffffffffa04c4a3c] intel_plane_duplicate_state+0x2c/0xa0 [i915]            } hitcount:        461  bytes_req:      62696486    { call_site: [ffffffffa029070e] drm_vma_node_allow+0x2e/0xd0 [drm]                      } hitcount:       1541  bytes_req:      61640487    { call_site: [ffffffff815f8d7b] sk_prot_alloc+0xcb/0x1b0                                } hitcount:         57  bytes_req:      57456488    .489    .490    .491    { call_site: [ffffffff8109524a] alloc_fair_sched_group+0x5a/0x1a0                       } hitcount:          2  bytes_req:        128492    { call_site: [ffffffffa027b921] drm_vm_open_locked+0x31/0xa0 [drm]                      } hitcount:          3  bytes_req:         96493    { call_site: [ffffffff8122e266] proc_self_follow_link+0x76/0xb0                         } hitcount:          8  bytes_req:         96494    { call_site: [ffffffff81213e80] load_elf_binary+0x240/0x1650                            } hitcount:          3  bytes_req:         84495    { call_site: [ffffffff8154bc62] usb_control_msg+0x42/0x110                              } hitcount:          1  bytes_req:          8496    { call_site: [ffffffffa00bf6fe] hidraw_send_report+0x7e/0x1a0 [hid]                     } hitcount:          1  bytes_req:          7497    { call_site: [ffffffffa00bf1ca] hidraw_report_event+0x8a/0x120 [hid]                    } hitcount:          1  bytes_req:          7498 499    Totals:500        Hits: 26098501        Entries: 64502        Dropped: 0503 504  We can also add multiple fields to the 'values' parameter.  For505  example, we might want to see the total number of bytes allocated506  alongside bytes requested, and display the result sorted by bytes507  allocated in a descending order::508 509    # echo 'hist:keys=call_site.sym:values=bytes_req,bytes_alloc:sort=bytes_alloc.descending' > \510           /sys/kernel/tracing/events/kmem/kmalloc/trigger511 512    # cat /sys/kernel/tracing/events/kmem/kmalloc/hist513    # trigger info: hist:keys=call_site.sym:vals=bytes_req,bytes_alloc:sort=bytes_alloc.descending:size=2048 [active]514 515    { call_site: [ffffffffa046041c] i915_gem_execbuffer2 [i915]                   } hitcount:       7403  bytes_req:    4084360  bytes_alloc:    5958016516    { call_site: [ffffffff811e2a1b] seq_buf_alloc                                 } hitcount:        541  bytes_req:    2213968  bytes_alloc:    2228224517    { call_site: [ffffffffa0489a66] intel_ring_begin [i915]                       } hitcount:       7404  bytes_req:    1066176  bytes_alloc:    1421568518    { call_site: [ffffffffa045e7c4] i915_gem_do_execbuffer.isra.23 [i915]         } hitcount:       1565  bytes_req:     557368  bytes_alloc:    1037760519    { call_site: [ffffffff8125847d] ext4_htree_store_dirent                       } hitcount:       9557  bytes_req:     595778  bytes_alloc:     695744520    { call_site: [ffffffffa045e646] i915_gem_do_execbuffer.isra.23 [i915]         } hitcount:       5839  bytes_req:     430680  bytes_alloc:     470400521    { call_site: [ffffffffa04c4a3c] intel_plane_duplicate_state [i915]            } hitcount:       2388  bytes_req:     324768  bytes_alloc:     458496522    { call_site: [ffffffffa02911f2] drm_modeset_lock_crtc [drm]                   } hitcount:       3911  bytes_req:     219016  bytes_alloc:     250304523    { call_site: [ffffffff815f8d7b] sk_prot_alloc                                 } hitcount:        235  bytes_req:     236880  bytes_alloc:     240640524    { call_site: [ffffffff8137e559] sg_kmalloc                                    } hitcount:        557  bytes_req:     169024  bytes_alloc:     221760525    { call_site: [ffffffffa00b7c06] hid_report_raw_event [hid]                    } hitcount:       9378  bytes_req:     187548  bytes_alloc:     206312526    { call_site: [ffffffffa04a580c] intel_crtc_page_flip [i915]                   } hitcount:       1519  bytes_req:     157976  bytes_alloc:     194432527    .528    .529    .530    { call_site: [ffffffff8109bd3b] sched_autogroup_create_attach                 } hitcount:          2  bytes_req:        144  bytes_alloc:        192531    { call_site: [ffffffff81097ee8] alloc_rt_sched_group                          } hitcount:          2  bytes_req:        128  bytes_alloc:        128532    { call_site: [ffffffff8109524a] alloc_fair_sched_group                        } hitcount:          2  bytes_req:        128  bytes_alloc:        128533    { call_site: [ffffffff81095225] alloc_fair_sched_group                        } hitcount:          2  bytes_req:        128  bytes_alloc:        128534    { call_site: [ffffffff81097ec2] alloc_rt_sched_group                          } hitcount:          2  bytes_req:        128  bytes_alloc:        128535    { call_site: [ffffffff81213e80] load_elf_binary                               } hitcount:          3  bytes_req:         84  bytes_alloc:         96536    { call_site: [ffffffff81079a2e] kthread_create_on_node                        } hitcount:          1  bytes_req:         56  bytes_alloc:         64537    { call_site: [ffffffffa00bf6fe] hidraw_send_report [hid]                      } hitcount:          1  bytes_req:          7  bytes_alloc:          8538    { call_site: [ffffffff8154bc62] usb_control_msg                               } hitcount:          1  bytes_req:          8  bytes_alloc:          8539    { call_site: [ffffffffa00bf1ca] hidraw_report_event [hid]                     } hitcount:          1  bytes_req:          7  bytes_alloc:          8540 541    Totals:542        Hits: 66598543        Entries: 65544        Dropped: 0545 546  Finally, to finish off our kmalloc example, instead of simply having547  the hist trigger display symbolic call_sites, we can have the hist548  trigger additionally display the complete set of kernel stack traces549  that led to each call_site.  To do that, we simply use the special550  value 'common_stacktrace' for the key parameter::551 552    # echo 'hist:keys=common_stacktrace:values=bytes_req,bytes_alloc:sort=bytes_alloc' > \553           /sys/kernel/tracing/events/kmem/kmalloc/trigger554 555  The above trigger will use the kernel stack trace in effect when an556  event is triggered as the key for the hash table.  This allows the557  enumeration of every kernel callpath that led up to a particular558  event, along with a running total of any of the event fields for559  that event.  Here we tally bytes requested and bytes allocated for560  every callpath in the system that led up to a kmalloc (in this case561  every callpath to a kmalloc for a kernel compile)::562 563    # cat /sys/kernel/tracing/events/kmem/kmalloc/hist564    # trigger info: hist:keys=common_stacktrace:vals=bytes_req,bytes_alloc:sort=bytes_alloc:size=2048 [active]565 566    { common_stacktrace:567         __kmalloc_track_caller+0x10b/0x1a0568         kmemdup+0x20/0x50569         hidraw_report_event+0x8a/0x120 [hid]570         hid_report_raw_event+0x3ea/0x440 [hid]571         hid_input_report+0x112/0x190 [hid]572         hid_irq_in+0xc2/0x260 [usbhid]573         __usb_hcd_giveback_urb+0x72/0x120574         usb_giveback_urb_bh+0x9e/0xe0575         tasklet_hi_action+0xf8/0x100576         __do_softirq+0x114/0x2c0577         irq_exit+0xa5/0xb0578         do_IRQ+0x5a/0xf0579         ret_from_intr+0x0/0x30580         cpuidle_enter+0x17/0x20581         cpu_startup_entry+0x315/0x3e0582         rest_init+0x7c/0x80583    } hitcount:          3  bytes_req:         21  bytes_alloc:         24584    { common_stacktrace:585         __kmalloc_track_caller+0x10b/0x1a0586         kmemdup+0x20/0x50587         hidraw_report_event+0x8a/0x120 [hid]588         hid_report_raw_event+0x3ea/0x440 [hid]589         hid_input_report+0x112/0x190 [hid]590         hid_irq_in+0xc2/0x260 [usbhid]591         __usb_hcd_giveback_urb+0x72/0x120592         usb_giveback_urb_bh+0x9e/0xe0593         tasklet_hi_action+0xf8/0x100594         __do_softirq+0x114/0x2c0595         irq_exit+0xa5/0xb0596         do_IRQ+0x5a/0xf0597         ret_from_intr+0x0/0x30598    } hitcount:          3  bytes_req:         21  bytes_alloc:         24599    { common_stacktrace:600         kmem_cache_alloc_trace+0xeb/0x150601         aa_alloc_task_context+0x27/0x40602         apparmor_cred_prepare+0x1f/0x50603         security_prepare_creds+0x16/0x20604         prepare_creds+0xdf/0x1a0605         SyS_capset+0xb5/0x200606         system_call_fastpath+0x12/0x6a607    } hitcount:          1  bytes_req:         32  bytes_alloc:         32608    .609    .610    .611    { common_stacktrace:612         __kmalloc+0x11b/0x1b0613         i915_gem_execbuffer2+0x6c/0x2c0 [i915]614         drm_ioctl+0x349/0x670 [drm]615         do_vfs_ioctl+0x2f0/0x4f0616         SyS_ioctl+0x81/0xa0617         system_call_fastpath+0x12/0x6a618    } hitcount:      17726  bytes_req:   13944120  bytes_alloc:   19593808619    { common_stacktrace:620         __kmalloc+0x11b/0x1b0621         load_elf_phdrs+0x76/0xa0622         load_elf_binary+0x102/0x1650623         search_binary_handler+0x97/0x1d0624         do_execveat_common.isra.34+0x551/0x6e0625         SyS_execve+0x3a/0x50626         return_from_execve+0x0/0x23627    } hitcount:      33348  bytes_req:   17152128  bytes_alloc:   20226048628    { common_stacktrace:629         kmem_cache_alloc_trace+0xeb/0x150630         apparmor_file_alloc_security+0x27/0x40631         security_file_alloc+0x16/0x20632         get_empty_filp+0x93/0x1c0633         path_openat+0x31/0x5f0634         do_filp_open+0x3a/0x90635         do_sys_open+0x128/0x220636         SyS_open+0x1e/0x20637         system_call_fastpath+0x12/0x6a638    } hitcount:    4766422  bytes_req:    9532844  bytes_alloc:   38131376639    { common_stacktrace:640         __kmalloc+0x11b/0x1b0641         seq_buf_alloc+0x1b/0x50642         seq_read+0x2cc/0x370643         proc_reg_read+0x3d/0x80644         __vfs_read+0x28/0xe0645         vfs_read+0x86/0x140646         SyS_read+0x46/0xb0647         system_call_fastpath+0x12/0x6a648    } hitcount:      19133  bytes_req:   78368768  bytes_alloc:   78368768649 650    Totals:651        Hits: 6085872652        Entries: 253653        Dropped: 0654 655  If you key a hist trigger on common_pid, in order for example to656  gather and display sorted totals for each process, you can use the657  special .execname modifier to display the executable names for the658  processes in the table rather than raw pids.  The example below659  keeps a per-process sum of total bytes read::660 661    # echo 'hist:key=common_pid.execname:val=count:sort=count.descending' > \662           /sys/kernel/tracing/events/syscalls/sys_enter_read/trigger663 664    # cat /sys/kernel/tracing/events/syscalls/sys_enter_read/hist665    # trigger info: hist:keys=common_pid.execname:vals=count:sort=count.descending:size=2048 [active]666 667    { common_pid: gnome-terminal  [      3196] } hitcount:        280  count:    1093512668    { common_pid: Xorg            [      1309] } hitcount:        525  count:     256640669    { common_pid: compiz          [      2889] } hitcount:         59  count:     254400670    { common_pid: bash            [      8710] } hitcount:          3  count:      66369671    { common_pid: dbus-daemon-lau [      8703] } hitcount:         49  count:      47739672    { common_pid: irqbalance      [      1252] } hitcount:         27  count:      27648673    { common_pid: 01ifupdown      [      8705] } hitcount:          3  count:      17216674    { common_pid: dbus-daemon     [       772] } hitcount:         10  count:      12396675    { common_pid: Socket Thread   [      8342] } hitcount:         11  count:      11264676    { common_pid: nm-dhcp-client. [      8701] } hitcount:          6  count:       7424677    { common_pid: gmain           [      1315] } hitcount:         18  count:       6336678    .679    .680    .681    { common_pid: postgres        [      1892] } hitcount:          2  count:         32682    { common_pid: postgres        [      1891] } hitcount:          2  count:         32683    { common_pid: gmain           [      8704] } hitcount:          2  count:         32684    { common_pid: upstart-dbus-br [      2740] } hitcount:         21  count:         21685    { common_pid: nm-dispatcher.a [      8696] } hitcount:          1  count:         16686    { common_pid: indicator-datet [      2904] } hitcount:          1  count:         16687    { common_pid: gdbus           [      2998] } hitcount:          1  count:         16688    { common_pid: rtkit-daemon    [      2052] } hitcount:          1  count:          8689    { common_pid: init            [         1] } hitcount:          2  count:          2690 691    Totals:692        Hits: 2116693        Entries: 51694        Dropped: 0695 696  Similarly, if you key a hist trigger on syscall id, for example to697  gather and display a list of systemwide syscall hits, you can use698  the special .syscall modifier to display the syscall names rather699  than raw ids.  The example below keeps a running total of syscall700  counts for the system during the run::701 702    # echo 'hist:key=id.syscall:val=hitcount' > \703           /sys/kernel/tracing/events/raw_syscalls/sys_enter/trigger704 705    # cat /sys/kernel/tracing/events/raw_syscalls/sys_enter/hist706    # trigger info: hist:keys=id.syscall:vals=hitcount:sort=hitcount:size=2048 [active]707 708    { id: sys_fsync                     [ 74] } hitcount:          1709    { id: sys_newuname                  [ 63] } hitcount:          1710    { id: sys_prctl                     [157] } hitcount:          1711    { id: sys_statfs                    [137] } hitcount:          1712    { id: sys_symlink                   [ 88] } hitcount:          1713    { id: sys_sendmmsg                  [307] } hitcount:          1714    { id: sys_semctl                    [ 66] } hitcount:          1715    { id: sys_readlink                  [ 89] } hitcount:          3716    { id: sys_bind                      [ 49] } hitcount:          3717    { id: sys_getsockname               [ 51] } hitcount:          3718    { id: sys_unlink                    [ 87] } hitcount:          3719    { id: sys_rename                    [ 82] } hitcount:          4720    { id: unknown_syscall               [ 58] } hitcount:          4721    { id: sys_connect                   [ 42] } hitcount:          4722    { id: sys_getpid                    [ 39] } hitcount:          4723    .724    .725    .726    { id: sys_rt_sigprocmask            [ 14] } hitcount:        952727    { id: sys_futex                     [202] } hitcount:       1534728    { id: sys_write                     [  1] } hitcount:       2689729    { id: sys_setitimer                 [ 38] } hitcount:       2797730    { id: sys_read                      [  0] } hitcount:       3202731    { id: sys_select                    [ 23] } hitcount:       3773732    { id: sys_writev                    [ 20] } hitcount:       4531733    { id: sys_poll                      [  7] } hitcount:       8314734    { id: sys_recvmsg                   [ 47] } hitcount:      13738735    { id: sys_ioctl                     [ 16] } hitcount:      21843736 737    Totals:738        Hits: 67612739        Entries: 72740        Dropped: 0741 742  The syscall counts above provide a rough overall picture of system743  call activity on the system; we can see for example that the most744  popular system call on this system was the 'sys_ioctl' system call.745 746  We can use 'compound' keys to refine that number and provide some747  further insight as to which processes exactly contribute to the748  overall ioctl count.749 750  The command below keeps a hitcount for every unique combination of751  system call id and pid - the end result is essentially a table752  that keeps a per-pid sum of system call hits.  The results are753  sorted using the system call id as the primary key, and the754  hitcount sum as the secondary key::755 756    # echo 'hist:key=id.syscall,common_pid.execname:val=hitcount:sort=id,hitcount' > \757           /sys/kernel/tracing/events/raw_syscalls/sys_enter/trigger758 759    # cat /sys/kernel/tracing/events/raw_syscalls/sys_enter/hist760    # trigger info: hist:keys=id.syscall,common_pid.execname:vals=hitcount:sort=id.syscall,hitcount:size=2048 [active]761 762    { id: sys_read                      [  0], common_pid: rtkit-daemon    [      1877] } hitcount:          1763    { id: sys_read                      [  0], common_pid: gdbus           [      2976] } hitcount:          1764    { id: sys_read                      [  0], common_pid: console-kit-dae [      3400] } hitcount:          1765    { id: sys_read                      [  0], common_pid: postgres        [      1865] } hitcount:          1766    { id: sys_read                      [  0], common_pid: deja-dup-monito [      3543] } hitcount:          2767    { id: sys_read                      [  0], common_pid: NetworkManager  [       890] } hitcount:          2768    { id: sys_read                      [  0], common_pid: evolution-calen [      3048] } hitcount:          2769    { id: sys_read                      [  0], common_pid: postgres        [      1864] } hitcount:          2770    { id: sys_read                      [  0], common_pid: nm-applet       [      3022] } hitcount:          2771    { id: sys_read                      [  0], common_pid: whoopsie        [      1212] } hitcount:          2772    .773    .774    .775    { id: sys_ioctl                     [ 16], common_pid: bash            [      8479] } hitcount:          1776    { id: sys_ioctl                     [ 16], common_pid: bash            [      3472] } hitcount:         12777    { id: sys_ioctl                     [ 16], common_pid: gnome-terminal  [      3199] } hitcount:         16778    { id: sys_ioctl                     [ 16], common_pid: Xorg            [      1267] } hitcount:       1808779    { id: sys_ioctl                     [ 16], common_pid: compiz          [      2994] } hitcount:       5580780    .781    .782    .783    { id: sys_waitid                    [247], common_pid: upstart-dbus-br [      2690] } hitcount:          3784    { id: sys_waitid                    [247], common_pid: upstart-dbus-br [      2688] } hitcount:         16785    { id: sys_inotify_add_watch         [254], common_pid: gmain           [       975] } hitcount:          2786    { id: sys_inotify_add_watch         [254], common_pid: gmain           [      3204] } hitcount:          4787    { id: sys_inotify_add_watch         [254], common_pid: gmain           [      2888] } hitcount:          4788    { id: sys_inotify_add_watch         [254], common_pid: gmain           [      3003] } hitcount:          4789    { id: sys_inotify_add_watch         [254], common_pid: gmain           [      2873] } hitcount:          4790    { id: sys_inotify_add_watch         [254], common_pid: gmain           [      3196] } hitcount:          6791    { id: sys_openat                    [257], common_pid: java            [      2623] } hitcount:          2792    { id: sys_eventfd2                  [290], common_pid: ibus-ui-gtk3    [      2760] } hitcount:          4793    { id: sys_eventfd2                  [290], common_pid: compiz          [      2994] } hitcount:          6794 795    Totals:796        Hits: 31536797        Entries: 323798        Dropped: 0799 800  The above list does give us a breakdown of the ioctl syscall by801  pid, but it also gives us quite a bit more than that, which we802  don't really care about at the moment.  Since we know the syscall803  id for sys_ioctl (16, displayed next to the sys_ioctl name), we804  can use that to filter out all the other syscalls::805 806    # echo 'hist:key=id.syscall,common_pid.execname:val=hitcount:sort=id,hitcount if id == 16' > \807           /sys/kernel/tracing/events/raw_syscalls/sys_enter/trigger808 809    # cat /sys/kernel/tracing/events/raw_syscalls/sys_enter/hist810    # trigger info: hist:keys=id.syscall,common_pid.execname:vals=hitcount:sort=id.syscall,hitcount:size=2048 if id == 16 [active]811 812    { id: sys_ioctl                     [ 16], common_pid: gmain           [      2769] } hitcount:          1813    { id: sys_ioctl                     [ 16], common_pid: evolution-addre [      8571] } hitcount:          1814    { id: sys_ioctl                     [ 16], common_pid: gmain           [      3003] } hitcount:          1815    { id: sys_ioctl                     [ 16], common_pid: gmain           [      2781] } hitcount:          1816    { id: sys_ioctl                     [ 16], common_pid: gmain           [      2829] } hitcount:          1817    { id: sys_ioctl                     [ 16], common_pid: bash            [      8726] } hitcount:          1818    { id: sys_ioctl                     [ 16], common_pid: bash            [      8508] } hitcount:          1819    { id: sys_ioctl                     [ 16], common_pid: gmain           [      2970] } hitcount:          1820    { id: sys_ioctl                     [ 16], common_pid: gmain           [      2768] } hitcount:          1821    .822    .823    .824    { id: sys_ioctl                     [ 16], common_pid: pool            [      8559] } hitcount:         45825    { id: sys_ioctl                     [ 16], common_pid: pool            [      8555] } hitcount:         48826    { id: sys_ioctl                     [ 16], common_pid: pool            [      8551] } hitcount:         48827    { id: sys_ioctl                     [ 16], common_pid: avahi-daemon    [       896] } hitcount:         66828    { id: sys_ioctl                     [ 16], common_pid: Xorg            [      1267] } hitcount:      26674829    { id: sys_ioctl                     [ 16], common_pid: compiz          [      2994] } hitcount:      73443830 831    Totals:832        Hits: 101162833        Entries: 103834        Dropped: 0835 836  The above output shows that 'compiz' and 'Xorg' are far and away837  the heaviest ioctl callers (which might lead to questions about838  whether they really need to be making all those calls and to839  possible avenues for further investigation.)840 841  The compound key examples used a key and a sum value (hitcount) to842  sort the output, but we can just as easily use two keys instead.843  Here's an example where we use a compound key composed of the the844  common_pid and size event fields.  Sorting with pid as the primary845  key and 'size' as the secondary key allows us to display an846  ordered summary of the recvfrom sizes, with counts, received by847  each process::848 849    # echo 'hist:key=common_pid.execname,size:val=hitcount:sort=common_pid,size' > \850           /sys/kernel/tracing/events/syscalls/sys_enter_recvfrom/trigger851 852    # cat /sys/kernel/tracing/events/syscalls/sys_enter_recvfrom/hist853    # trigger info: hist:keys=common_pid.execname,size:vals=hitcount:sort=common_pid.execname,size:size=2048 [active]854 855    { common_pid: smbd            [       784], size:          4 } hitcount:          1856    { common_pid: dnsmasq         [      1412], size:       4096 } hitcount:        672857    { common_pid: postgres        [      1796], size:       1000 } hitcount:          6858    { common_pid: postgres        [      1867], size:       1000 } hitcount:         10859    { common_pid: bamfdaemon      [      2787], size:         28 } hitcount:          2860    { common_pid: bamfdaemon      [      2787], size:      14360 } hitcount:          1861    { common_pid: compiz          [      2994], size:          8 } hitcount:          1862    { common_pid: compiz          [      2994], size:         20 } hitcount:         11863    { common_pid: gnome-terminal  [      3199], size:          4 } hitcount:          2864    { common_pid: firefox         [      8817], size:          4 } hitcount:          1865    { common_pid: firefox         [      8817], size:          8 } hitcount:          5866    { common_pid: firefox         [      8817], size:        588 } hitcount:          2867    { common_pid: firefox         [      8817], size:        628 } hitcount:          1868    { common_pid: firefox         [      8817], size:       6944 } hitcount:          1869    { common_pid: firefox         [      8817], size:     408880 } hitcount:          2870    { common_pid: firefox         [      8822], size:          8 } hitcount:          2871    { common_pid: firefox         [      8822], size:        160 } hitcount:          2872    { common_pid: firefox         [      8822], size:        320 } hitcount:          2873    { common_pid: firefox         [      8822], size:        352 } hitcount:          1874    .875    .876    .877    { common_pid: pool            [      8923], size:       1960 } hitcount:         10878    { common_pid: pool            [      8923], size:       2048 } hitcount:         10879    { common_pid: pool            [      8924], size:       1960 } hitcount:         10880    { common_pid: pool            [      8924], size:       2048 } hitcount:         10881    { common_pid: pool            [      8928], size:       1964 } hitcount:          4882    { common_pid: pool            [      8928], size:       1965 } hitcount:          2883    { common_pid: pool            [      8928], size:       2048 } hitcount:          6884    { common_pid: pool            [      8929], size:       1982 } hitcount:          1885    { common_pid: pool            [      8929], size:       2048 } hitcount:          1886 887    Totals:888        Hits: 2016889        Entries: 224890        Dropped: 0891 892  The above example also illustrates the fact that although a compound893  key is treated as a single entity for hashing purposes, the sub-keys894  it's composed of can be accessed independently.895 896  The next example uses a string field as the hash key and897  demonstrates how you can manually pause and continue a hist trigger.898  In this example, we'll aggregate fork counts and don't expect a899  large number of entries in the hash table, so we'll drop it to a900  much smaller number, say 256::901 902    # echo 'hist:key=child_comm:val=hitcount:size=256' > \903           /sys/kernel/tracing/events/sched/sched_process_fork/trigger904 905    # cat /sys/kernel/tracing/events/sched/sched_process_fork/hist906    # trigger info: hist:keys=child_comm:vals=hitcount:sort=hitcount:size=256 [active]907 908    { child_comm: dconf worker                        } hitcount:          1909    { child_comm: ibus-daemon                         } hitcount:          1910    { child_comm: whoopsie                            } hitcount:          1911    { child_comm: smbd                                } hitcount:          1912    { child_comm: gdbus                               } hitcount:          1913    { child_comm: kthreadd                            } hitcount:          1914    { child_comm: dconf worker                        } hitcount:          1915    { child_comm: evolution-alarm                     } hitcount:          2916    { child_comm: Socket Thread                       } hitcount:          2917    { child_comm: postgres                            } hitcount:          2918    { child_comm: bash                                } hitcount:          3919    { child_comm: compiz                              } hitcount:          3920    { child_comm: evolution-sourc                     } hitcount:          4921    { child_comm: dhclient                            } hitcount:          4922    { child_comm: pool                                } hitcount:          5923    { child_comm: nm-dispatcher.a                     } hitcount:          8924    { child_comm: firefox                             } hitcount:          8925    { child_comm: dbus-daemon                         } hitcount:          8926    { child_comm: glib-pacrunner                      } hitcount:         10927    { child_comm: evolution                           } hitcount:         23928 929    Totals:930        Hits: 89931        Entries: 20932        Dropped: 0933 934  If we want to pause the hist trigger, we can simply append :pause to935  the command that started the trigger.  Notice that the trigger info936  displays as [paused]::937 938    # echo 'hist:key=child_comm:val=hitcount:size=256:pause' >> \939           /sys/kernel/tracing/events/sched/sched_process_fork/trigger940 941    # cat /sys/kernel/tracing/events/sched/sched_process_fork/hist942    # trigger info: hist:keys=child_comm:vals=hitcount:sort=hitcount:size=256 [paused]943 944    { child_comm: dconf worker                        } hitcount:          1945    { child_comm: kthreadd                            } hitcount:          1946    { child_comm: dconf worker                        } hitcount:          1947    { child_comm: gdbus                               } hitcount:          1948    { child_comm: ibus-daemon                         } hitcount:          1949    { child_comm: Socket Thread                       } hitcount:          2950    { child_comm: evolution-alarm                     } hitcount:          2951    { child_comm: smbd                                } hitcount:          2952    { child_comm: bash                                } hitcount:          3953    { child_comm: whoopsie                            } hitcount:          3954    { child_comm: compiz                              } hitcount:          3955    { child_comm: evolution-sourc                     } hitcount:          4956    { child_comm: pool                                } hitcount:          5957    { child_comm: postgres                            } hitcount:          6958    { child_comm: firefox                             } hitcount:          8959    { child_comm: dhclient                            } hitcount:         10960    { child_comm: emacs                               } hitcount:         12961    { child_comm: dbus-daemon                         } hitcount:         20962    { child_comm: nm-dispatcher.a                     } hitcount:         20963    { child_comm: evolution                           } hitcount:         35964    { child_comm: glib-pacrunner                      } hitcount:         59965 966    Totals:967        Hits: 199968        Entries: 21969        Dropped: 0970 971  To manually continue having the trigger aggregate events, append972  :cont instead.  Notice that the trigger info displays as [active]973  again, and the data has changed::974 975    # echo 'hist:key=child_comm:val=hitcount:size=256:cont' >> \976           /sys/kernel/tracing/events/sched/sched_process_fork/trigger977 978    # cat /sys/kernel/tracing/events/sched/sched_process_fork/hist979    # trigger info: hist:keys=child_comm:vals=hitcount:sort=hitcount:size=256 [active]980 981    { child_comm: dconf worker                        } hitcount:          1982    { child_comm: dconf worker                        } hitcount:          1983    { child_comm: kthreadd                            } hitcount:          1984    { child_comm: gdbus                               } hitcount:          1985    { child_comm: ibus-daemon                         } hitcount:          1986    { child_comm: Socket Thread                       } hitcount:          2987    { child_comm: evolution-alarm                     } hitcount:          2988    { child_comm: smbd                                } hitcount:          2989    { child_comm: whoopsie                            } hitcount:          3990    { child_comm: compiz                              } hitcount:          3991    { child_comm: evolution-sourc                     } hitcount:          4992    { child_comm: bash                                } hitcount:          5993    { child_comm: pool                                } hitcount:          5994    { child_comm: postgres                            } hitcount:          6995    { child_comm: firefox                             } hitcount:          8996    { child_comm: dhclient                            } hitcount:         11997    { child_comm: emacs                               } hitcount:         12998    { child_comm: dbus-daemon                         } hitcount:         22999    { child_comm: nm-dispatcher.a                     } hitcount:         221000    { child_comm: evolution                           } hitcount:         351001    { child_comm: glib-pacrunner                      } hitcount:         591002 1003    Totals:1004        Hits: 2061005        Entries: 211006        Dropped: 01007 1008  The previous example showed how to start and stop a hist trigger by1009  appending 'pause' and 'continue' to the hist trigger command.  A1010  hist trigger can also be started in a paused state by initially1011  starting the trigger with ':pause' appended.  This allows you to1012  start the trigger only when you're ready to start collecting data1013  and not before.  For example, you could start the trigger in a1014  paused state, then unpause it and do something you want to measure,1015  then pause the trigger again when done.1016 1017  Of course, doing this manually can be difficult and error-prone, but1018  it is possible to automatically start and stop a hist trigger based1019  on some condition, via the enable_hist and disable_hist triggers.1020 1021  For example, suppose we wanted to take a look at the relative1022  weights in terms of skb length for each callpath that leads to a1023  netif_receive_skb event when downloading a decent-sized file using1024  wget.1025 1026  First we set up an initially paused stacktrace trigger on the1027  netif_receive_skb event::1028 1029    # echo 'hist:key=common_stacktrace:vals=len:pause' > \1030           /sys/kernel/tracing/events/net/netif_receive_skb/trigger1031 1032  Next, we set up an 'enable_hist' trigger on the sched_process_exec1033  event, with an 'if filename==/usr/bin/wget' filter.  The effect of1034  this new trigger is that it will 'unpause' the hist trigger we just1035  set up on netif_receive_skb if and only if it sees a1036  sched_process_exec event with a filename of '/usr/bin/wget'.  When1037  that happens, all netif_receive_skb events are aggregated into a1038  hash table keyed on stacktrace::1039 1040    # echo 'enable_hist:net:netif_receive_skb if filename==/usr/bin/wget' > \1041           /sys/kernel/tracing/events/sched/sched_process_exec/trigger1042 1043  The aggregation continues until the netif_receive_skb is paused1044  again, which is what the following disable_hist event does by1045  creating a similar setup on the sched_process_exit event, using the1046  filter 'comm==wget'::1047 1048    # echo 'disable_hist:net:netif_receive_skb if comm==wget' > \1049           /sys/kernel/tracing/events/sched/sched_process_exit/trigger1050 1051  Whenever a process exits and the comm field of the disable_hist1052  trigger filter matches 'comm==wget', the netif_receive_skb hist1053  trigger is disabled.1054 1055  The overall effect is that netif_receive_skb events are aggregated1056  into the hash table for only the duration of the wget.  Executing a1057  wget command and then listing the 'hist' file will display the1058  output generated by the wget command::1059 1060    $ wget https://www.kernel.org/pub/linux/kernel/v3.x/patch-3.19.xz1061 1062    # cat /sys/kernel/tracing/events/net/netif_receive_skb/hist1063    # trigger info: hist:keys=common_stacktrace:vals=len:sort=hitcount:size=2048 [paused]1064 1065    { common_stacktrace:1066         __netif_receive_skb_core+0x46d/0x9901067         __netif_receive_skb+0x18/0x601068         netif_receive_skb_internal+0x23/0x901069         napi_gro_receive+0xc8/0x1001070         ieee80211_deliver_skb+0xd6/0x270 [mac80211]1071         ieee80211_rx_handlers+0xccf/0x22f0 [mac80211]1072         ieee80211_prepare_and_rx_handle+0x4e7/0xc40 [mac80211]1073         ieee80211_rx+0x31d/0x900 [mac80211]1074         iwlagn_rx_reply_rx+0x3db/0x6f0 [iwldvm]1075         iwl_rx_dispatch+0x8e/0xf0 [iwldvm]1076         iwl_pcie_irq_handler+0xe3c/0x12f0 [iwlwifi]1077         irq_thread_fn+0x20/0x501078         irq_thread+0x11f/0x1501079         kthread+0xd2/0xf01080         ret_from_fork+0x42/0x701081    } hitcount:         85  len:      288841082    { common_stacktrace:1083         __netif_receive_skb_core+0x46d/0x9901084         __netif_receive_skb+0x18/0x601085         netif_receive_skb_internal+0x23/0x901086         napi_gro_complete+0xa4/0xe01087         dev_gro_receive+0x23a/0x3601088         napi_gro_receive+0x30/0x1001089         ieee80211_deliver_skb+0xd6/0x270 [mac80211]1090         ieee80211_rx_handlers+0xccf/0x22f0 [mac80211]1091         ieee80211_prepare_and_rx_handle+0x4e7/0xc40 [mac80211]1092         ieee80211_rx+0x31d/0x900 [mac80211]1093         iwlagn_rx_reply_rx+0x3db/0x6f0 [iwldvm]1094         iwl_rx_dispatch+0x8e/0xf0 [iwldvm]1095         iwl_pcie_irq_handler+0xe3c/0x12f0 [iwlwifi]1096         irq_thread_fn+0x20/0x501097         irq_thread+0x11f/0x1501098         kthread+0xd2/0xf01099    } hitcount:         98  len:     6643291100    { common_stacktrace:1101         __netif_receive_skb_core+0x46d/0x9901102         __netif_receive_skb+0x18/0x601103         process_backlog+0xa8/0x1501104         net_rx_action+0x15d/0x3401105         __do_softirq+0x114/0x2c01106         do_softirq_own_stack+0x1c/0x301107         do_softirq+0x65/0x701108         __local_bh_enable_ip+0xb5/0xc01109         ip_finish_output+0x1f4/0x8401110         ip_output+0x6b/0xc01111         ip_local_out_sk+0x31/0x401112         ip_send_skb+0x1a/0x501113         udp_send_skb+0x173/0x2a01114         udp_sendmsg+0x2bf/0x9f01115         inet_sendmsg+0x64/0xa01116         sock_sendmsg+0x3d/0x501117    } hitcount:        115  len:      130301118    { common_stacktrace:1119         __netif_receive_skb_core+0x46d/0x9901120         __netif_receive_skb+0x18/0x601121         netif_receive_skb_internal+0x23/0x901122         napi_gro_complete+0xa4/0xe01123         napi_gro_flush+0x6d/0x901124         iwl_pcie_irq_handler+0x92a/0x12f0 [iwlwifi]1125         irq_thread_fn+0x20/0x501126         irq_thread+0x11f/0x1501127         kthread+0xd2/0xf01128         ret_from_fork+0x42/0x701129    } hitcount:        934  len:    55122121130 1131    Totals:1132        Hits: 12321133        Entries: 41134        Dropped: 01135 1136  The above shows all the netif_receive_skb callpaths and their total1137  lengths for the duration of the wget command.1138 1139  The 'clear' hist trigger param can be used to clear the hash table.1140  Suppose we wanted to try another run of the previous example but1141  this time also wanted to see the complete list of events that went1142  into the histogram.  In order to avoid having to set everything up1143  again, we can just clear the histogram first::1144 1145    # echo 'hist:key=common_stacktrace:vals=len:clear' >> \1146           /sys/kernel/tracing/events/net/netif_receive_skb/trigger1147 1148  Just to verify that it is in fact cleared, here's what we now see in1149  the hist file::1150 1151    # cat /sys/kernel/tracing/events/net/netif_receive_skb/hist1152    # trigger info: hist:keys=common_stacktrace:vals=len:sort=hitcount:size=2048 [paused]1153 1154    Totals:1155        Hits: 01156        Entries: 01157        Dropped: 01158 1159  Since we want to see the detailed list of every netif_receive_skb1160  event occurring during the new run, which are in fact the same1161  events being aggregated into the hash table, we add some additional1162  'enable_event' events to the triggering sched_process_exec and1163  sched_process_exit events as such::1164 1165    # echo 'enable_event:net:netif_receive_skb if filename==/usr/bin/wget' > \1166           /sys/kernel/tracing/events/sched/sched_process_exec/trigger1167 1168    # echo 'disable_event:net:netif_receive_skb if comm==wget' > \1169           /sys/kernel/tracing/events/sched/sched_process_exit/trigger1170 1171  If you read the trigger files for the sched_process_exec and1172  sched_process_exit triggers, you should see two triggers for each:1173  one enabling/disabling the hist aggregation and the other1174  enabling/disabling the logging of events::1175 1176    # cat /sys/kernel/tracing/events/sched/sched_process_exec/trigger1177    enable_event:net:netif_receive_skb:unlimited if filename==/usr/bin/wget1178    enable_hist:net:netif_receive_skb:unlimited if filename==/usr/bin/wget1179 1180    # cat /sys/kernel/tracing/events/sched/sched_process_exit/trigger1181    enable_event:net:netif_receive_skb:unlimited if comm==wget1182    disable_hist:net:netif_receive_skb:unlimited if comm==wget1183 1184  In other words, whenever either of the sched_process_exec or1185  sched_process_exit events is hit and matches 'wget', it enables or1186  disables both the histogram and the event log, and what you end up1187  with is a hash table and set of events just covering the specified1188  duration.  Run the wget command again::1189 1190    $ wget https://www.kernel.org/pub/linux/kernel/v3.x/patch-3.19.xz1191 1192  Displaying the 'hist' file should show something similar to what you1193  saw in the last run, but this time you should also see the1194  individual events in the trace file::1195 1196    # cat /sys/kernel/tracing/trace1197 1198    # tracer: nop1199    #1200    # entries-in-buffer/entries-written: 183/1426   #P:41201    #1202    #                              _-----=> irqs-off1203    #                             / _----=> need-resched1204    #                            | / _---=> hardirq/softirq1205    #                            || / _--=> preempt-depth1206    #                            ||| /     delay1207    #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION1208    #              | |       |   ||||       |         |1209                wget-15108 [000] ..s1 31769.606929: netif_receive_skb: dev=lo skbaddr=ffff88009c353100 len=601210                wget-15108 [000] ..s1 31769.606999: netif_receive_skb: dev=lo skbaddr=ffff88009c353200 len=601211             dnsmasq-1382  [000] ..s1 31769.677652: netif_receive_skb: dev=lo skbaddr=ffff88009c352b00 len=1301212             dnsmasq-1382  [000] ..s1 31769.685917: netif_receive_skb: dev=lo skbaddr=ffff88009c352200 len=1381213    ##### CPU 2 buffer started ####1214      irq/29-iwlwifi-559   [002] ..s. 31772.031529: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d433d00 len=29481215      irq/29-iwlwifi-559   [002] ..s. 31772.031572: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d432200 len=15001216      irq/29-iwlwifi-559   [002] ..s. 31772.032196: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d433100 len=29481217      irq/29-iwlwifi-559   [002] ..s. 31772.032761: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d433000 len=29481218      irq/29-iwlwifi-559   [002] ..s. 31772.033220: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d432e00 len=15001219    .1220    .1221    .1222 1223  The following example demonstrates how multiple hist triggers can be1224  attached to a given event.  This capability can be useful for1225  creating a set of different summaries derived from the same set of1226  events, or for comparing the effects of different filters, among1227  other things::1228 1229    # echo 'hist:keys=skbaddr.hex:vals=len if len < 0' >> \1230           /sys/kernel/tracing/events/net/netif_receive_skb/trigger1231    # echo 'hist:keys=skbaddr.hex:vals=len if len > 4096' >> \1232           /sys/kernel/tracing/events/net/netif_receive_skb/trigger1233    # echo 'hist:keys=skbaddr.hex:vals=len if len == 256' >> \1234           /sys/kernel/tracing/events/net/netif_receive_skb/trigger1235    # echo 'hist:keys=skbaddr.hex:vals=len' >> \1236           /sys/kernel/tracing/events/net/netif_receive_skb/trigger1237    # echo 'hist:keys=len:vals=common_preempt_count' >> \1238           /sys/kernel/tracing/events/net/netif_receive_skb/trigger1239 1240  The above set of commands create four triggers differing only in1241  their filters, along with a completely different though fairly1242  nonsensical trigger.  Note that in order to append multiple hist1243  triggers to the same file, you should use the '>>' operator to1244  append them ('>' will also add the new hist trigger, but will remove1245  any existing hist triggers beforehand).1246 1247  Displaying the contents of the 'hist' file for the event shows the1248  contents of all five histograms::1249 1250    # cat /sys/kernel/tracing/events/net/netif_receive_skb/hist1251 1252    # event histogram1253    #1254    # trigger info: hist:keys=len:vals=hitcount,common_preempt_count:sort=hitcount:size=2048 [active]1255    #1256 1257    { len:        176 } hitcount:          1  common_preempt_count:          01258    { len:        223 } hitcount:          1  common_preempt_count:          01259    { len:       4854 } hitcount:          1  common_preempt_count:          01260    { len:        395 } hitcount:          1  common_preempt_count:          01261    { len:        177 } hitcount:          1  common_preempt_count:          01262    { len:        446 } hitcount:          1  common_preempt_count:          01263    { len:       1601 } hitcount:          1  common_preempt_count:          01264    .1265    .1266    .1267    { len:       1280 } hitcount:         66  common_preempt_count:          01268    { len:        116 } hitcount:         81  common_preempt_count:         401269    { len:        708 } hitcount:        112  common_preempt_count:          01270    { len:         46 } hitcount:        221  common_preempt_count:          01271    { len:       1264 } hitcount:        458  common_preempt_count:          01272 1273    Totals:1274        Hits: 14281275        Entries: 1471276        Dropped: 01277 1278 1279    # event histogram1280    #1281    # trigger info: hist:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 [active]1282    #1283 1284    { skbaddr: ffff8800baee5e00 } hitcount:          1  len:        1301285    { skbaddr: ffff88005f3d5600 } hitcount:          1  len:       12801286    { skbaddr: ffff88005f3d4900 } hitcount:          1  len:       12801287    { skbaddr: ffff88009fed6300 } hitcount:          1  len:        1151288    { skbaddr: ffff88009fe0ad00 } hitcount:          1  len:        1151289    { skbaddr: ffff88008cdb1900 } hitcount:          1  len:         461290    { skbaddr: ffff880064b5ef00 } hitcount:          1  len:        1181291    { skbaddr: ffff880044e3c700 } hitcount:          1  len:         601292    { skbaddr: ffff880100065900 } hitcount:          1  len:         461293    { skbaddr: ffff8800d46bd500 } hitcount:          1  len:        1161294    { skbaddr: ffff88005f3d5f00 } hitcount:          1  len:       12801295    { skbaddr: ffff880100064700 } hitcount:          1  len:        3651296    { skbaddr: ffff8800badb6f00 } hitcount:          1  len:         601297    .1298    .1299    .1300    { skbaddr: ffff88009fe0be00 } hitcount:         27  len:      246771301    { skbaddr: ffff88009fe0a400 } hitcount:         27  len:      230521302    { skbaddr: ffff88009fe0b700 } hitcount:         31  len:      255891303    { skbaddr: ffff88009fe0b600 } hitcount:         32  len:      273261304    { skbaddr: ffff88006a462800 } hitcount:         68  len:      716781305    { skbaddr: ffff88006a463700 } hitcount:         70  len:      726781306    { skbaddr: ffff88006a462b00 } hitcount:         71  len:      775891307    { skbaddr: ffff88006a463600 } hitcount:         73  len:      713071308    { skbaddr: ffff88006a462200 } hitcount:         81  len:      810321309 1310    Totals:1311        Hits: 14511312        Entries: 3181313        Dropped: 01314 1315 1316    # event histogram1317    #1318    # trigger info: hist:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 if len == 256 [active]1319    #1320 1321 1322    Totals:1323        Hits: 01324        Entries: 01325        Dropped: 01326 1327 1328    # event histogram1329    #1330    # trigger info: hist:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 if len > 4096 [active]1331    #1332 1333    { skbaddr: ffff88009fd2c300 } hitcount:          1  len:       72121334    { skbaddr: ffff8800d2bcce00 } hitcount:          1  len:       72121335    { skbaddr: ffff8800d2bcd700 } hitcount:          1  len:       72121336    { skbaddr: ffff8800d2bcda00 } hitcount:          1  len:      214921337    { skbaddr: ffff8800ae2e2d00 } hitcount:          1  len:       72121338    { skbaddr: ffff8800d2bcdb00 } hitcount:          1  len:       72121339    { skbaddr: ffff88006a4df500 } hitcount:          1  len:       48541340    { skbaddr: ffff88008ce47b00 } hitcount:          1  len:      186361341    { skbaddr: ffff8800ae2e2200 } hitcount:          1  len:      129241342    { skbaddr: ffff88005f3e1000 } hitcount:          1  len:       43561343    { skbaddr: ffff8800d2bcdc00 } hitcount:          2  len:      244201344    { skbaddr: ffff8800d2bcc200 } hitcount:          2  len:      129961345 1346    Totals:1347        Hits: 141348        Entries: 121349        Dropped: 01350 1351 1352    # event histogram1353    #1354    # trigger info: hist:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 if len < 0 [active]1355    #1356 1357 1358    Totals:1359        Hits: 01360        Entries: 01361        Dropped: 01362 1363  Named triggers can be used to have triggers share a common set of1364  histogram data.  This capability is mostly useful for combining the1365  output of events generated by tracepoints contained inside inline1366  functions, but names can be used in a hist trigger on any event.1367  For example, these two triggers when hit will update the same 'len'1368  field in the shared 'foo' histogram data::1369 1370    # echo 'hist:name=foo:keys=skbaddr.hex:vals=len' > \1371           /sys/kernel/tracing/events/net/netif_receive_skb/trigger1372    # echo 'hist:name=foo:keys=skbaddr.hex:vals=len' > \1373           /sys/kernel/tracing/events/net/netif_rx/trigger1374 1375  You can see that they're updating common histogram data by reading1376  each event's hist files at the same time::1377 1378    # cat /sys/kernel/tracing/events/net/netif_receive_skb/hist;1379      cat /sys/kernel/tracing/events/net/netif_rx/hist1380 1381    # event histogram1382    #1383    # trigger info: hist:name=foo:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 [active]1384    #1385 1386    { skbaddr: ffff88000ad53500 } hitcount:          1  len:         461387    { skbaddr: ffff8800af5a1500 } hitcount:          1  len:         761388    { skbaddr: ffff8800d62a1900 } hitcount:          1  len:         461389    { skbaddr: ffff8800d2bccb00 } hitcount:          1  len:        4681390    { skbaddr: ffff8800d3c69900 } hitcount:          1  len:         461391    { skbaddr: ffff88009ff09100 } hitcount:          1  len:         521392    { skbaddr: ffff88010f13ab00 } hitcount:          1  len:        1681393    { skbaddr: ffff88006a54f400 } hitcount:          1  len:         461394    { skbaddr: ffff8800d2bcc500 } hitcount:          1  len:        2601395    { skbaddr: ffff880064505000 } hitcount:          1  len:         461396    { skbaddr: ffff8800baf24e00 } hitcount:          1  len:         321397    { skbaddr: ffff88009fe0ad00 } hitcount:          1  len:         461398    { skbaddr: ffff8800d3edff00 } hitcount:          1  len:         441399    { skbaddr: ffff88009fe0b400 } hitcount:          1  len:        1681400    { skbaddr: ffff8800a1c55a00 } hitcount:          1  len:         401401    { skbaddr: ffff8800d2bcd100 } hitcount:          1  len:         401402    { skbaddr: ffff880064505f00 } hitcount:          1  len:        1741403    { skbaddr: ffff8800a8bff200 } hitcount:          1  len:        1601404    { skbaddr: ffff880044e3cc00 } hitcount:          1  len:         761405    { skbaddr: ffff8800a8bfe700 } hitcount:          1  len:         461406    { skbaddr: ffff8800d2bcdc00 } hitcount:          1  len:         321407    { skbaddr: ffff8800a1f64800 } hitcount:          1  len:         461408    { skbaddr: ffff8800d2bcde00 } hitcount:          1  len:        9881409    { skbaddr: ffff88006a5dea00 } hitcount:          1  len:         461410    { skbaddr: ffff88002e37a200 } hitcount:          1  len:         441411    { skbaddr: ffff8800a1f32c00 } hitcount:          2  len:        6761412    { skbaddr: ffff88000ad52600 } hitcount:          2  len:        1071413    { skbaddr: ffff8800a1f91e00 } hitcount:          2  len:         921414    { skbaddr: ffff8800af5a0200 } hitcount:          2  len:        1421415    { skbaddr: ffff8800d2bcc600 } hitcount:          2  len:        2201416    { skbaddr: ffff8800ba36f500 } hitcount:          2  len:         921417    { skbaddr: ffff8800d021f800 } hitcount:          2  len:         921418    { skbaddr: ffff8800a1f33600 } hitcount:          2  len:        6751419    { skbaddr: ffff8800a8bfff00 } hitcount:          3  len:        1381420    { skbaddr: ffff8800d62a1300 } hitcount:          3  len:        1381421    { skbaddr: ffff88002e37a100 } hitcount:          4  len:        1841422    { skbaddr: ffff880064504400 } hitcount:          4  len:        1841423    { skbaddr: ffff8800a8bfec00 } hitcount:          4  len:        1841424    { skbaddr: ffff88000ad53700 } hitcount:          5  len:        2301425    { skbaddr: ffff8800d2bcdb00 } hitcount:          5  len:        1961426    { skbaddr: ffff8800a1f90000 } hitcount:          6  len:        2761427    { skbaddr: ffff88006a54f900 } hitcount:          6  len:        2761428 1429    Totals:1430        Hits: 811431        Entries: 421432        Dropped: 01433    # event histogram1434    #1435    # trigger info: hist:name=foo:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 [active]1436    #1437 1438    { skbaddr: ffff88000ad53500 } hitcount:          1  len:         461439    { skbaddr: ffff8800af5a1500 } hitcount:          1  len:         761440    { skbaddr: ffff8800d62a1900 } hitcount:          1  len:         461441    { skbaddr: ffff8800d2bccb00 } hitcount:          1  len:        4681442    { skbaddr: ffff8800d3c69900 } hitcount:          1  len:         461443    { skbaddr: ffff88009ff09100 } hitcount:          1  len:         521444    { skbaddr: ffff88010f13ab00 } hitcount:          1  len:        1681445    { skbaddr: ffff88006a54f400 } hitcount:          1  len:         461446    { skbaddr: ffff8800d2bcc500 } hitcount:          1  len:        2601447    { skbaddr: ffff880064505000 } hitcount:          1  len:         461448    { skbaddr: ffff8800baf24e00 } hitcount:          1  len:         321449    { skbaddr: ffff88009fe0ad00 } hitcount:          1  len:         461450    { skbaddr: ffff8800d3edff00 } hitcount:          1  len:         441451    { skbaddr: ffff88009fe0b400 } hitcount:          1  len:        1681452    { skbaddr: ffff8800a1c55a00 } hitcount:          1  len:         401453    { skbaddr: ffff8800d2bcd100 } hitcount:          1  len:         401454    { skbaddr: ffff880064505f00 } hitcount:          1  len:        1741455    { skbaddr: ffff8800a8bff200 } hitcount:          1  len:        1601456    { skbaddr: ffff880044e3cc00 } hitcount:          1  len:         761457    { skbaddr: ffff8800a8bfe700 } hitcount:          1  len:         461458    { skbaddr: ffff8800d2bcdc00 } hitcount:          1  len:         321459    { skbaddr: ffff8800a1f64800 } hitcount:          1  len:         461460    { skbaddr: ffff8800d2bcde00 } hitcount:          1  len:        9881461    { skbaddr: ffff88006a5dea00 } hitcount:          1  len:         461462    { skbaddr: ffff88002e37a200 } hitcount:          1  len:         441463    { skbaddr: ffff8800a1f32c00 } hitcount:          2  len:        6761464    { skbaddr: ffff88000ad52600 } hitcount:          2  len:        1071465    { skbaddr: ffff8800a1f91e00 } hitcount:          2  len:         921466    { skbaddr: ffff8800af5a0200 } hitcount:          2  len:        1421467    { skbaddr: ffff8800d2bcc600 } hitcount:          2  len:        2201468    { skbaddr: ffff8800ba36f500 } hitcount:          2  len:         921469    { skbaddr: ffff8800d021f800 } hitcount:          2  len:         921470    { skbaddr: ffff8800a1f33600 } hitcount:          2  len:        6751471    { skbaddr: ffff8800a8bfff00 } hitcount:          3  len:        1381472    { skbaddr: ffff8800d62a1300 } hitcount:          3  len:        1381473    { skbaddr: ffff88002e37a100 } hitcount:          4  len:        1841474    { skbaddr: ffff880064504400 } hitcount:          4  len:        1841475    { skbaddr: ffff8800a8bfec00 } hitcount:          4  len:        1841476    { skbaddr: ffff88000ad53700 } hitcount:          5  len:        2301477    { skbaddr: ffff8800d2bcdb00 } hitcount:          5  len:        1961478    { skbaddr: ffff8800a1f90000 } hitcount:          6  len:        2761479    { skbaddr: ffff88006a54f900 } hitcount:          6  len:        2761480 1481    Totals:1482        Hits: 811483        Entries: 421484        Dropped: 01485 1486  And here's an example that shows how to combine histogram data from1487  any two events even if they don't share any 'compatible' fields1488  other than 'hitcount' and 'common_stacktrace'.  These commands create a1489  couple of triggers named 'bar' using those fields::1490 1491    # echo 'hist:name=bar:key=common_stacktrace:val=hitcount' > \1492           /sys/kernel/tracing/events/sched/sched_process_fork/trigger1493    # echo 'hist:name=bar:key=common_stacktrace:val=hitcount' > \1494          /sys/kernel/tracing/events/net/netif_rx/trigger1495 1496  And displaying the output of either shows some interesting if1497  somewhat confusing output::1498 1499    # cat /sys/kernel/tracing/events/sched/sched_process_fork/hist1500    # cat /sys/kernel/tracing/events/net/netif_rx/hist1501 1502    # event histogram1503    #1504    # trigger info: hist:name=bar:keys=common_stacktrace:vals=hitcount:sort=hitcount:size=2048 [active]1505    #1506 1507    { common_stacktrace:1508             kernel_clone+0x18e/0x3301509             kernel_thread+0x29/0x301510             kthreadd+0x154/0x1b01511             ret_from_fork+0x3f/0x701512    } hitcount:          11513    { common_stacktrace:1514             netif_rx_internal+0xb2/0xd01515             netif_rx_ni+0x20/0x701516             dev_loopback_xmit+0xaa/0xd01517             ip_mc_output+0x126/0x2401518             ip_local_out_sk+0x31/0x401519             igmp_send_report+0x1e9/0x2301520             igmp_timer_expire+0xe9/0x1201521             call_timer_fn+0x39/0xf01522             run_timer_softirq+0x1e1/0x2901523             __do_softirq+0xfd/0x2901524             irq_exit+0x98/0xb01525             smp_apic_timer_interrupt+0x4a/0x601526             apic_timer_interrupt+0x6d/0x801527             cpuidle_enter+0x17/0x201528             call_cpuidle+0x3b/0x601529             cpu_startup_entry+0x22d/0x3101530    } hitcount:          11531    { common_stacktrace:1532             netif_rx_internal+0xb2/0xd01533             netif_rx_ni+0x20/0x701534             dev_loopback_xmit+0xaa/0xd01535             ip_mc_output+0x17f/0x2401536             ip_local_out_sk+0x31/0x401537             ip_send_skb+0x1a/0x501538             udp_send_skb+0x13e/0x2701539             udp_sendmsg+0x2bf/0x9801540             inet_sendmsg+0x67/0xa01541             sock_sendmsg+0x38/0x501542             SYSC_sendto+0xef/0x1701543             SyS_sendto+0xe/0x101544             entry_SYSCALL_64_fastpath+0x12/0x6a1545    } hitcount:          21546    { common_stacktrace:1547             netif_rx_internal+0xb2/0xd01548             netif_rx+0x1c/0x601549             loopback_xmit+0x6c/0xb01550             dev_hard_start_xmit+0x219/0x3a01551             __dev_queue_xmit+0x415/0x4f01552             dev_queue_xmit_sk+0x13/0x201553             ip_finish_output2+0x237/0x3401554             ip_finish_output+0x113/0x1d01555             ip_output+0x66/0xc01556             ip_local_out_sk+0x31/0x401557             ip_send_skb+0x1a/0x501558             udp_send_skb+0x16d/0x2701559             udp_sendmsg+0x2bf/0x9801560             inet_sendmsg+0x67/0xa01561             sock_sendmsg+0x38/0x501562             ___sys_sendmsg+0x14e/0x2701563    } hitcount:         761564    { common_stacktrace:1565             netif_rx_internal+0xb2/0xd01566             netif_rx+0x1c/0x601567             loopback_xmit+0x6c/0xb01568             dev_hard_start_xmit+0x219/0x3a01569             __dev_queue_xmit+0x415/0x4f01570             dev_queue_xmit_sk+0x13/0x201571             ip_finish_output2+0x237/0x3401572             ip_finish_output+0x113/0x1d01573             ip_output+0x66/0xc01574             ip_local_out_sk+0x31/0x401575             ip_send_skb+0x1a/0x501576             udp_send_skb+0x16d/0x2701577             udp_sendmsg+0x2bf/0x9801578             inet_sendmsg+0x67/0xa01579             sock_sendmsg+0x38/0x501580             ___sys_sendmsg+0x269/0x2701581    } hitcount:         771582    { common_stacktrace:1583             netif_rx_internal+0xb2/0xd01584             netif_rx+0x1c/0x601585             loopback_xmit+0x6c/0xb01586             dev_hard_start_xmit+0x219/0x3a01587             __dev_queue_xmit+0x415/0x4f01588             dev_queue_xmit_sk+0x13/0x201589             ip_finish_output2+0x237/0x3401590             ip_finish_output+0x113/0x1d01591             ip_output+0x66/0xc01592             ip_local_out_sk+0x31/0x401593             ip_send_skb+0x1a/0x501594             udp_send_skb+0x16d/0x2701595             udp_sendmsg+0x2bf/0x9801596             inet_sendmsg+0x67/0xa01597             sock_sendmsg+0x38/0x501598             SYSC_sendto+0xef/0x1701599    } hitcount:         881600    { common_stacktrace:1601             kernel_clone+0x18e/0x3301602             SyS_clone+0x19/0x201603             entry_SYSCALL_64_fastpath+0x12/0x6a1604    } hitcount:        2441605 1606    Totals:1607        Hits: 4891608        Entries: 71609        Dropped: 01610 16112.2 Inter-event hist triggers1612-----------------------------1613 1614Inter-event hist triggers are hist triggers that combine values from1615one or more other events and create a histogram using that data.  Data1616from an inter-event histogram can in turn become the source for1617further combined histograms, thus providing a chain of related1618histograms, which is important for some applications.1619 1620The most important example of an inter-event quantity that can be used1621in this manner is latency, which is simply a difference in timestamps1622between two events.  Although latency is the most important1623inter-event quantity, note that because the support is completely1624general across the trace event subsystem, any event field can be used1625in an inter-event quantity.1626 1627An example of a histogram that combines data from other histograms1628into a useful chain would be a 'wakeupswitch latency' histogram that1629combines a 'wakeup latency' histogram and a 'switch latency'1630histogram.1631 1632Normally, a hist trigger specification consists of a (possibly1633compound) key along with one or more numeric values, which are1634continually updated sums associated with that key.  A histogram1635specification in this case consists of individual key and value1636specifications that refer to trace event fields associated with a1637single event type.1638 1639The inter-event hist trigger extension allows fields from multiple1640events to be referenced and combined into a multi-event histogram1641specification.  In support of this overall goal, a few enabling1642features have been added to the hist trigger support:1643 1644  - In order to compute an inter-event quantity, a value from one1645    event needs to saved and then referenced from another event.  This1646    requires the introduction of support for histogram 'variables'.1647 1648  - The computation of inter-event quantities and their combination1649    require some minimal amount of support for applying simple1650    expressions to variables (+ and -).1651 1652  - A histogram consisting of inter-event quantities isn't logically a1653    histogram on either event (so having the 'hist' file for either1654    event host the histogram output doesn't really make sense).  To1655    address the idea that the histogram is associated with a1656    combination of events, support is added allowing the creation of1657    'synthetic' events that are events derived from other events.1658    These synthetic events are full-fledged events just like any other1659    and can be used as such, as for instance to create the1660    'combination' histograms mentioned previously.1661 1662  - A set of 'actions' can be associated with histogram entries -1663    these can be used to generate the previously mentioned synthetic1664    events, but can also be used for other purposes, such as for1665    example saving context when a 'max' latency has been hit.1666 1667  - Trace events don't have a 'timestamp' associated with them, but1668    there is an implicit timestamp saved along with an event in the1669    underlying ftrace ring buffer.  This timestamp is now exposed as a1670    a synthetic field named 'common_timestamp' which can be used in1671    histograms as if it were any other event field; it isn't an actual1672    field in the trace format but rather is a synthesized value that1673    nonetheless can be used as if it were an actual field.  By default1674    it is in units of nanoseconds; appending '.usecs' to a1675    common_timestamp field changes the units to microseconds.1676 1677A note on inter-event timestamps: If common_timestamp is used in a1678histogram, the trace buffer is automatically switched over to using1679absolute timestamps and the "global" trace clock, in order to avoid1680bogus timestamp differences with other clocks that aren't coherent1681across CPUs.  This can be overridden by specifying one of the other1682trace clocks instead, using the "clock=XXX" hist trigger attribute,1683where XXX is any of the clocks listed in the tracing/trace_clock1684pseudo-file.1685 1686These features are described in more detail in the following sections.1687 16882.2.1 Histogram Variables1689-------------------------1690 1691Variables are simply named locations used for saving and retrieving1692values between matching events.  A 'matching' event is defined as an1693event that has a matching key - if a variable is saved for a histogram1694entry corresponding to that key, any subsequent event with a matching1695key can access that variable.1696 1697A variable's value is normally available to any subsequent event until1698it is set to something else by a subsequent event.  The one exception1699to that rule is that any variable used in an expression is essentially1700'read-once' - once it's used by an expression in a subsequent event,1701it's reset to its 'unset' state, which means it can't be used again1702unless it's set again.  This ensures not only that an event doesn't1703use an uninitialized variable in a calculation, but that that variable1704is used only once and not for any unrelated subsequent match.1705 1706The basic syntax for saving a variable is to simply prefix a unique1707variable name not corresponding to any keyword along with an '=' sign1708to any event field.1709 1710Either keys or values can be saved and retrieved in this way.  This1711creates a variable named 'ts0' for a histogram entry with the key1712'next_pid'::1713 1714  # echo 'hist:keys=next_pid:vals=$ts0:ts0=common_timestamp ... >> \1715	event/trigger1716 1717The ts0 variable can be accessed by any subsequent event having the1718same pid as 'next_pid'.1719 1720Variable references are formed by prepending the variable name with1721the '$' sign.  Thus for example, the ts0 variable above would be1722referenced as '$ts0' in expressions.1723 1724Because 'vals=' is used, the common_timestamp variable value above1725will also be summed as a normal histogram value would (though for a1726timestamp it makes little sense).1727 1728The below shows that a key value can also be saved in the same way::1729 1730  # echo 'hist:timer_pid=common_pid:key=timer_pid ...' >> event/trigger1731 1732If a variable isn't a key variable or prefixed with 'vals=', the1733associated event field will be saved in a variable but won't be summed1734as a value::1735 1736  # echo 'hist:keys=next_pid:ts1=common_timestamp ...' >> event/trigger1737 1738Multiple variables can be assigned at the same time.  The below would1739result in both ts0 and b being created as variables, with both1740common_timestamp and field1 additionally being summed as values::1741 1742  # echo 'hist:keys=pid:vals=$ts0,$b:ts0=common_timestamp,b=field1 ...' >> \1743	event/trigger1744 1745Note that variable assignments can appear either preceding or1746following their use.  The command below behaves identically to the1747command above::1748 1749  # echo 'hist:keys=pid:ts0=common_timestamp,b=field1:vals=$ts0,$b ...' >> \1750	event/trigger1751 1752Any number of variables not bound to a 'vals=' prefix can also be1753assigned by simply separating them with colons.  Below is the same1754thing but without the values being summed in the histogram::1755 1756  # echo 'hist:keys=pid:ts0=common_timestamp:b=field1 ...' >> event/trigger1757 1758Variables set as above can be referenced and used in expressions on1759another event.1760 1761For example, here's how a latency can be calculated::1762 1763  # echo 'hist:keys=pid,prio:ts0=common_timestamp ...' >> event1/trigger1764  # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp-$ts0 ...' >> event2/trigger1765 1766In the first line above, the event's timestamp is saved into the1767variable ts0.  In the next line, ts0 is subtracted from the second1768event's timestamp to produce the latency, which is then assigned into1769yet another variable, 'wakeup_lat'.  The hist trigger below in turn1770makes use of the wakeup_lat variable to compute a combined latency1771using the same key and variable from yet another event::1772 1773  # echo 'hist:key=pid:wakeupswitch_lat=$wakeup_lat+$switchtime_lat ...' >> event3/trigger1774 1775Expressions support the use of addition, subtraction, multiplication and1776division operators (+-\*/).1777 1778Note if division by zero cannot be detected at parse time (i.e. the1779divisor is not a constant), the result will be -1.1780 1781Numeric constants can also be used directly in an expression::1782 1783  # echo 'hist:keys=next_pid:timestamp_secs=common_timestamp/1000000 ...' >> event/trigger1784 1785or assigned to a variable and referenced in a subsequent expression::1786 1787  # echo 'hist:keys=next_pid:us_per_sec=1000000 ...' >> event/trigger1788  # echo 'hist:keys=next_pid:timestamp_secs=common_timestamp/$us_per_sec ...' >> event/trigger1789 1790Variables can even hold stacktraces, which are useful with synthetic events.1791 17922.2.2 Synthetic Events1793----------------------1794 1795Synthetic events are user-defined events generated from hist trigger1796variables or fields associated with one or more other events.  Their1797purpose is to provide a mechanism for displaying data spanning1798multiple events consistent with the existing and already familiar1799usage for normal events.1800 1801To define a synthetic event, the user writes a simple specification1802consisting of the name of the new event along with one or more1803variables and their types, which can be any valid field type,1804separated by semicolons, to the tracing/synthetic_events file.1805 1806See synth_field_size() for available types.1807 1808If field_name contains [n], the field is considered to be a static array.1809 1810If field_names contains[] (no subscript), the field is considered to1811be a dynamic array, which will only take as much space in the event as1812is required to hold the array.1813 1814A string field can be specified using either the static notation:1815 1816  char name[32];1817 1818Or the dynamic:1819 1820  char name[];1821 1822The size limit for either is 256.1823 1824For instance, the following creates a new event named 'wakeup_latency'1825with 3 fields: lat, pid, and prio.  Each of those fields is simply a1826variable reference to a variable on another event::1827 1828  # echo 'wakeup_latency \1829          u64 lat; \1830          pid_t pid; \1831	  int prio' >> \1832	  /sys/kernel/tracing/synthetic_events1833 1834Reading the tracing/synthetic_events file lists all the currently1835defined synthetic events, in this case the event defined above::1836 1837  # cat /sys/kernel/tracing/synthetic_events1838    wakeup_latency u64 lat; pid_t pid; int prio1839 1840An existing synthetic event definition can be removed by prepending1841the command that defined it with a '!'::1842 1843  # echo '!wakeup_latency u64 lat pid_t pid int prio' >> \1844    /sys/kernel/tracing/synthetic_events1845 1846At this point, there isn't yet an actual 'wakeup_latency' event1847instantiated in the event subsystem - for this to happen, a 'hist1848trigger action' needs to be instantiated and bound to actual fields1849and variables defined on other events (see Section 2.2.3 below on1850how that is done using hist trigger 'onmatch' action). Once that is1851done, the 'wakeup_latency' synthetic event instance is created.1852 1853The new event is created under the tracing/events/synthetic/ directory1854and looks and behaves just like any other event::1855 1856  # ls /sys/kernel/tracing/events/synthetic/wakeup_latency1857        enable  filter  format  hist  id  trigger1858 1859A histogram can now be defined for the new synthetic event::1860 1861  # echo 'hist:keys=pid,prio,lat.log2:sort=lat' >> \1862        /sys/kernel/tracing/events/synthetic/wakeup_latency/trigger1863 1864The above shows the latency "lat" in a power of 2 grouping.1865 1866Like any other event, once a histogram is enabled for the event, the1867output can be displayed by reading the event's 'hist' file::1868 1869  # cat /sys/kernel/tracing/events/synthetic/wakeup_latency/hist1870 1871  # event histogram1872  #1873  # trigger info: hist:keys=pid,prio,lat.log2:vals=hitcount:sort=lat.log2:size=2048 [active]1874  #1875 1876  { pid:       2035, prio:          9, lat: ~ 2^2  } hitcount:         431877  { pid:       2034, prio:          9, lat: ~ 2^2  } hitcount:         601878  { pid:       2029, prio:          9, lat: ~ 2^2  } hitcount:        9651879  { pid:       2034, prio:        120, lat: ~ 2^2  } hitcount:          91880  { pid:       2033, prio:        120, lat: ~ 2^2  } hitcount:          51881  { pid:       2030, prio:          9, lat: ~ 2^2  } hitcount:        3351882  { pid:       2030, prio:        120, lat: ~ 2^2  } hitcount:         101883  { pid:       2032, prio:        120, lat: ~ 2^2  } hitcount:          11884  { pid:       2035, prio:        120, lat: ~ 2^2  } hitcount:          21885  { pid:       2031, prio:          9, lat: ~ 2^2  } hitcount:        1761886  { pid:       2028, prio:        120, lat: ~ 2^2  } hitcount:         151887  { pid:       2033, prio:          9, lat: ~ 2^2  } hitcount:         911888  { pid:       2032, prio:          9, lat: ~ 2^2  } hitcount:        1251889  { pid:       2029, prio:        120, lat: ~ 2^2  } hitcount:          41890  { pid:       2031, prio:        120, lat: ~ 2^2  } hitcount:          31891  { pid:       2029, prio:        120, lat: ~ 2^3  } hitcount:          21892  { pid:       2035, prio:          9, lat: ~ 2^3  } hitcount:         411893  { pid:       2030, prio:        120, lat: ~ 2^3  } hitcount:          11894  { pid:       2032, prio:          9, lat: ~ 2^3  } hitcount:         321895  { pid:       2031, prio:          9, lat: ~ 2^3  } hitcount:         441896  { pid:       2034, prio:          9, lat: ~ 2^3  } hitcount:         401897  { pid:       2030, prio:          9, lat: ~ 2^3  } hitcount:         291898  { pid:       2033, prio:          9, lat: ~ 2^3  } hitcount:         311899  { pid:       2029, prio:          9, lat: ~ 2^3  } hitcount:         311900  { pid:       2028, prio:        120, lat: ~ 2^3  } hitcount:         181901  { pid:       2031, prio:        120, lat: ~ 2^3  } hitcount:          21902  { pid:       2028, prio:        120, lat: ~ 2^4  } hitcount:          11903  { pid:       2029, prio:          9, lat: ~ 2^4  } hitcount:          41904  { pid:       2031, prio:        120, lat: ~ 2^7  } hitcount:          11905  { pid:       2032, prio:        120, lat: ~ 2^7  } hitcount:          11906 1907  Totals:1908      Hits: 21221909      Entries: 301910      Dropped: 01911 1912 1913The latency values can also be grouped linearly by a given size with1914the ".buckets" modifier and specify a size (in this case groups of 10)::1915 1916  # echo 'hist:keys=pid,prio,lat.buckets=10:sort=lat' >> \1917        /sys/kernel/tracing/events/synthetic/wakeup_latency/trigger1918 1919  # event histogram1920  #1921  # trigger info: hist:keys=pid,prio,lat.buckets=10:vals=hitcount:sort=lat.buckets=10:size=2048 [active]1922  #1923 1924  { pid:       2067, prio:          9, lat: ~ 0-9 } hitcount:        2201925  { pid:       2068, prio:          9, lat: ~ 0-9 } hitcount:        1571926  { pid:       2070, prio:          9, lat: ~ 0-9 } hitcount:        1001927  { pid:       2067, prio:        120, lat: ~ 0-9 } hitcount:          61928  { pid:       2065, prio:        120, lat: ~ 0-9 } hitcount:          21929  { pid:       2066, prio:        120, lat: ~ 0-9 } hitcount:          21930  { pid:       2069, prio:          9, lat: ~ 0-9 } hitcount:        1221931  { pid:       2069, prio:        120, lat: ~ 0-9 } hitcount:          81932  { pid:       2070, prio:        120, lat: ~ 0-9 } hitcount:          11933  { pid:       2068, prio:        120, lat: ~ 0-9 } hitcount:          71934  { pid:       2066, prio:          9, lat: ~ 0-9 } hitcount:        3651935  { pid:       2064, prio:        120, lat: ~ 0-9 } hitcount:         351936  { pid:       2065, prio:          9, lat: ~ 0-9 } hitcount:        9981937  { pid:       2071, prio:          9, lat: ~ 0-9 } hitcount:         851938  { pid:       2065, prio:          9, lat: ~ 10-19 } hitcount:          21939  { pid:       2064, prio:        120, lat: ~ 10-19 } hitcount:          21940 1941  Totals:1942      Hits: 21121943      Entries: 161944      Dropped: 01945 1946To save stacktraces, create a synthetic event with a field of type "unsigned long[]"1947or even just "long[]". For example, to see how long a task is blocked in an1948uninterruptible state::1949 1950  # cd /sys/kernel/tracing1951  # echo 's:block_lat pid_t pid; u64 delta; unsigned long[] stack;' > dynamic_events1952  # echo 'hist:keys=next_pid:ts=common_timestamp.usecs,st=common_stacktrace  if prev_state == 2' >> events/sched/sched_switch/trigger1953  # echo 'hist:keys=prev_pid:delta=common_timestamp.usecs-$ts,s=$st:onmax($delta).trace(block_lat,prev_pid,$delta,$s)' >> events/sched/sched_switch/trigger1954  # echo 1 > events/synthetic/block_lat/enable1955  # cat trace1956 1957  # tracer: nop1958  #1959  # entries-in-buffer/entries-written: 2/2   #P:81960  #1961  #                                _-----=> irqs-off/BH-disabled1962  #                               / _----=> need-resched1963  #                              | / _---=> hardirq/softirq1964  #                              || / _--=> preempt-depth1965  #                              ||| / _-=> migrate-disable1966  #                              |||| /     delay1967  #           TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION1968  #              | |         |   |||||     |         |1969            <idle>-0       [005] d..4.   521.164922: block_lat: pid=0 delta=8322 stack=STACK:1970  => __schedule+0x448/0x7b01971  => schedule+0x5a/0xb01972  => io_schedule+0x42/0x701973  => bit_wait_io+0xd/0x601974  => __wait_on_bit+0x4b/0x1401975  => out_of_line_wait_on_bit+0x91/0xb01976  => jbd2_journal_commit_transaction+0x1679/0x1a701977  => kjournald2+0xa9/0x2801978  => kthread+0xe9/0x1101979  => ret_from_fork+0x2c/0x501980 1981             <...>-2       [004] d..4.   525.184257: block_lat: pid=2 delta=76 stack=STACK:1982  => __schedule+0x448/0x7b01983  => schedule+0x5a/0xb01984  => schedule_timeout+0x11a/0x1501985  => wait_for_completion_killable+0x144/0x1f01986  => __kthread_create_on_node+0xe7/0x1e01987  => kthread_create_on_node+0x51/0x701988  => create_worker+0xcc/0x1a01989  => worker_thread+0x2ad/0x3801990  => kthread+0xe9/0x1101991  => ret_from_fork+0x2c/0x501992 1993A synthetic event that has a stacktrace field may use it as a key in1994histogram::1995 1996  # echo 'hist:keys=delta.buckets=100,stack.stacktrace:sort=delta' > events/synthetic/block_lat/trigger1997  # cat events/synthetic/block_lat/hist1998 1999  # event histogram2000  #2001  # trigger info: hist:keys=delta.buckets=100,stack.stacktrace:vals=hitcount:sort=delta.buckets=100:size=2048 [active]2002  #2003  { delta: ~ 0-99, stack.stacktrace         __schedule+0xa19/0x15202004         schedule+0x6b/0x1102005         io_schedule+0x46/0x802006         bit_wait_io+0x11/0x802007         __wait_on_bit+0x4e/0x1202008         out_of_line_wait_on_bit+0x8d/0xb02009         __wait_on_buffer+0x33/0x402010         jbd2_journal_commit_transaction+0x155a/0x19b02011         kjournald2+0xab/0x2702012         kthread+0xfa/0x1302013         ret_from_fork+0x29/0x502014  } hitcount:          12015  { delta: ~ 0-99, stack.stacktrace         __schedule+0xa19/0x15202016         schedule+0x6b/0x1102017         io_schedule+0x46/0x802018         rq_qos_wait+0xd0/0x1702019         wbt_wait+0x9e/0xf02020         __rq_qos_throttle+0x25/0x402021         blk_mq_submit_bio+0x2c3/0x5b02022         __submit_bio+0xff/0x1902023         submit_bio_noacct_nocheck+0x25b/0x2b02024         submit_bio_noacct+0x20b/0x6002025         submit_bio+0x28/0x902026         ext4_bio_write_page+0x1e0/0x8c02027         mpage_submit_page+0x60/0x802028         mpage_process_page_bufs+0x16c/0x1802029         mpage_prepare_extent_to_map+0x23f/0x5302030  } hitcount:          12031  { delta: ~ 0-99, stack.stacktrace         __schedule+0xa19/0x15202032         schedule+0x6b/0x1102033         schedule_hrtimeout_range_clock+0x97/0x1102034         schedule_hrtimeout_range+0x13/0x202035         usleep_range_state+0x65/0x902036         __intel_wait_for_register+0x1c1/0x230 [i915]2037         intel_psr_wait_for_idle_locked+0x171/0x2a0 [i915]2038         intel_pipe_update_start+0x169/0x360 [i915]2039         intel_update_crtc+0x112/0x490 [i915]2040         skl_commit_modeset_enables+0x199/0x600 [i915]2041         intel_atomic_commit_tail+0x7c4/0x1080 [i915]2042         intel_atomic_commit_work+0x12/0x20 [i915]2043         process_one_work+0x21c/0x3f02044         worker_thread+0x50/0x3e02045         kthread+0xfa/0x1302046  } hitcount:          32047  { delta: ~ 0-99, stack.stacktrace         __schedule+0xa19/0x15202048         schedule+0x6b/0x1102049         schedule_timeout+0x11e/0x1602050         __wait_for_common+0x8f/0x1902051         wait_for_completion+0x24/0x302052         __flush_work.isra.0+0x1cc/0x3602053         flush_work+0xe/0x202054         drm_mode_rmfb+0x18b/0x1d0 [drm]2055         drm_mode_rmfb_ioctl+0x10/0x20 [drm]2056         drm_ioctl_kernel+0xb8/0x150 [drm]2057         drm_ioctl+0x243/0x560 [drm]2058         __x64_sys_ioctl+0x92/0xd02059         do_syscall_64+0x59/0x902060         entry_SYSCALL_64_after_hwframe+0x72/0xdc2061  } hitcount:          12062  { delta: ~ 0-99, stack.stacktrace         __schedule+0xa19/0x15202063         schedule+0x6b/0x1102064         schedule_timeout+0x87/0x1602065         __wait_for_common+0x8f/0x1902066         wait_for_completion_timeout+0x1d/0x302067         drm_atomic_helper_wait_for_flip_done+0x57/0x90 [drm_kms_helper]2068         intel_atomic_commit_tail+0x8ce/0x1080 [i915]2069         intel_atomic_commit_work+0x12/0x20 [i915]2070         process_one_work+0x21c/0x3f02071         worker_thread+0x50/0x3e02072         kthread+0xfa/0x1302073         ret_from_fork+0x29/0x502074  } hitcount:          12075  { delta: ~ 100-199, stack.stacktrace         __schedule+0xa19/0x15202076         schedule+0x6b/0x1102077         schedule_hrtimeout_range_clock+0x97/0x1102078         schedule_hrtimeout_range+0x13/0x202079         usleep_range_state+0x65/0x902080         pci_set_low_power_state+0x17f/0x1f02081         pci_set_power_state+0x49/0x2502082         pci_finish_runtime_suspend+0x4a/0x902083         pci_pm_runtime_suspend+0xcb/0x1b02084         __rpm_callback+0x48/0x1202085         rpm_callback+0x67/0x702086         rpm_suspend+0x167/0x7802087         rpm_idle+0x25a/0x3802088         pm_runtime_work+0x93/0xc02089         process_one_work+0x21c/0x3f02090  } hitcount:          12091 2092  Totals:2093    Hits: 102094    Entries: 72095    Dropped: 02096 20972.2.3 Hist trigger 'handlers' and 'actions'2098-------------------------------------------2099 2100A hist trigger 'action' is a function that's executed (in most cases2101conditionally) whenever a histogram entry is added or updated.2102 2103When a histogram entry is added or updated, a hist trigger 'handler'2104is what decides whether the corresponding action is actually invoked2105or not.2106 2107Hist trigger handlers and actions are paired together in the general2108form:2109 2110  <handler>.<action>2111 2112To specify a handler.action pair for a given event, simply specify2113that handler.action pair between colons in the hist trigger2114specification.2115 2116In theory, any handler can be combined with any action, but in2117practice, not every handler.action combination is currently supported;2118if a given handler.action combination isn't supported, the hist2119trigger will fail with -EINVAL;2120 2121The default 'handler.action' if none is explicitly specified is as it2122always has been, to simply update the set of values associated with an2123entry.  Some applications, however, may want to perform additional2124actions at that point, such as generate another event, or compare and2125save a maximum.2126 2127The supported handlers and actions are listed below, and each is2128described in more detail in the following paragraphs, in the context2129of descriptions of some common and useful handler.action combinations.2130 2131The available handlers are:2132 2133  - onmatch(matching.event)    - invoke action on any addition or update2134  - onmax(var)                 - invoke action if var exceeds current max2135  - onchange(var)              - invoke action if var changes2136 2137The available actions are:2138 2139  - trace(<synthetic_event_name>,param list)   - generate synthetic event2140  - save(field,...)                            - save current event fields2141  - snapshot()                                 - snapshot the trace buffer2142 2143The following commonly-used handler.action pairs are available:2144 2145  - onmatch(matching.event).trace(<synthetic_event_name>,param list)2146 2147    The 'onmatch(matching.event).trace(<synthetic_event_name>,param2148    list)' hist trigger action is invoked whenever an event matches2149    and the histogram entry would be added or updated.  It causes the2150    named synthetic event to be generated with the values given in the2151    'param list'.  The result is the generation of a synthetic event2152    that consists of the values contained in those variables at the2153    time the invoking event was hit.  For example, if the synthetic2154    event name is 'wakeup_latency', a wakeup_latency event is2155    generated using onmatch(event).trace(wakeup_latency,arg1,arg2).2156 2157    There is also an equivalent alternative form available for2158    generating synthetic events.  In this form, the synthetic event2159    name is used as if it were a function name.  For example, using2160    the 'wakeup_latency' synthetic event name again, the2161    wakeup_latency event would be generated by invoking it as if it2162    were a function call, with the event field values passed in as2163    arguments: onmatch(event).wakeup_latency(arg1,arg2).  The syntax2164    for this form is:2165 2166      onmatch(matching.event).<synthetic_event_name>(param list)2167 2168    In either case, the 'param list' consists of one or more2169    parameters which may be either variables or fields defined on2170    either the 'matching.event' or the target event.  The variables or2171    fields specified in the param list may be either fully-qualified2172    or unqualified.  If a variable is specified as unqualified, it2173    must be unique between the two events.  A field name used as a2174    param can be unqualified if it refers to the target event, but2175    must be fully qualified if it refers to the matching event.  A2176    fully-qualified name is of the form 'system.event_name.$var_name'2177    or 'system.event_name.field'.2178 2179    The 'matching.event' specification is simply the fully qualified2180    event name of the event that matches the target event for the2181    onmatch() functionality, in the form 'system.event_name'. Histogram2182    keys of both events are compared to find if events match. In case2183    multiple histogram keys are used, they all must match in the specified2184    order.2185 2186    Finally, the number and type of variables/fields in the 'param2187    list' must match the number and types of the fields in the2188    synthetic event being generated.2189 2190    As an example the below defines a simple synthetic event and uses2191    a variable defined on the sched_wakeup_new event as a parameter2192    when invoking the synthetic event.  Here we define the synthetic2193    event::2194 2195      # echo 'wakeup_new_test pid_t pid' >> \2196             /sys/kernel/tracing/synthetic_events2197 2198      # cat /sys/kernel/tracing/synthetic_events2199            wakeup_new_test pid_t pid2200 2201    The following hist trigger both defines the missing testpid2202    variable and specifies an onmatch() action that generates a2203    wakeup_new_test synthetic event whenever a sched_wakeup_new event2204    occurs, which because of the 'if comm == "cyclictest"' filter only2205    happens when the executable is cyclictest::2206 2207      # echo 'hist:keys=$testpid:testpid=pid:onmatch(sched.sched_wakeup_new).\2208              wakeup_new_test($testpid) if comm=="cyclictest"' >> \2209              /sys/kernel/tracing/events/sched/sched_wakeup_new/trigger2210 2211    Or, equivalently, using the 'trace' keyword syntax::2212 2213      # echo 'hist:keys=$testpid:testpid=pid:onmatch(sched.sched_wakeup_new).\2214              trace(wakeup_new_test,$testpid) if comm=="cyclictest"' >> \2215              /sys/kernel/tracing/events/sched/sched_wakeup_new/trigger2216 2217    Creating and displaying a histogram based on those events is now2218    just a matter of using the fields and new synthetic event in the2219    tracing/events/synthetic directory, as usual::2220 2221      # echo 'hist:keys=pid:sort=pid' >> \2222             /sys/kernel/tracing/events/synthetic/wakeup_new_test/trigger2223 2224    Running 'cyclictest' should cause wakeup_new events to generate2225    wakeup_new_test synthetic events which should result in histogram2226    output in the wakeup_new_test event's hist file::2227 2228      # cat /sys/kernel/tracing/events/synthetic/wakeup_new_test/hist2229 2230    A more typical usage would be to use two events to calculate a2231    latency.  The following example uses a set of hist triggers to2232    produce a 'wakeup_latency' histogram.2233 2234    First, we define a 'wakeup_latency' synthetic event::2235 2236      # echo 'wakeup_latency u64 lat; pid_t pid; int prio' >> \2237              /sys/kernel/tracing/synthetic_events2238 2239    Next, we specify that whenever we see a sched_waking event for a2240    cyclictest thread, save the timestamp in a 'ts0' variable::2241 2242      # echo 'hist:keys=$saved_pid:saved_pid=pid:ts0=common_timestamp.usecs \2243              if comm=="cyclictest"' >> \2244	      /sys/kernel/tracing/events/sched/sched_waking/trigger2245 2246    Then, when the corresponding thread is actually scheduled onto the2247    CPU by a sched_switch event (saved_pid matches next_pid), calculate2248    the latency and use that along with another variable and an event field2249    to generate a wakeup_latency synthetic event::2250 2251      # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0:\2252              onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,\2253	              $saved_pid,next_prio) if next_comm=="cyclictest"' >> \2254	      /sys/kernel/tracing/events/sched/sched_switch/trigger2255 2256    We also need to create a histogram on the wakeup_latency synthetic2257    event in order to aggregate the generated synthetic event data::2258 2259      # echo 'hist:keys=pid,prio,lat:sort=pid,lat' >> \2260              /sys/kernel/tracing/events/synthetic/wakeup_latency/trigger2261 2262    Finally, once we've run cyclictest to actually generate some2263    events, we can see the output by looking at the wakeup_latency2264    synthetic event's hist file::2265 2266      # cat /sys/kernel/tracing/events/synthetic/wakeup_latency/hist2267 2268  - onmax(var).save(field,..	.)2269 2270    The 'onmax(var).save(field,...)' hist trigger action is invoked2271    whenever the value of 'var' associated with a histogram entry2272    exceeds the current maximum contained in that variable.2273 2274    The end result is that the trace event fields specified as the2275    onmax.save() params will be saved if 'var' exceeds the current2276    maximum for that hist trigger entry.  This allows context from the2277    event that exhibited the new maximum to be saved for later2278    reference.  When the histogram is displayed, additional fields2279    displaying the saved values will be printed.2280 2281    As an example the below defines a couple of hist triggers, one for2282    sched_waking and another for sched_switch, keyed on pid.  Whenever2283    a sched_waking occurs, the timestamp is saved in the entry2284    corresponding to the current pid, and when the scheduler switches2285    back to that pid, the timestamp difference is calculated.  If the2286    resulting latency, stored in wakeup_lat, exceeds the current2287    maximum latency, the values specified in the save() fields are2288    recorded::2289 2290      # echo 'hist:keys=pid:ts0=common_timestamp.usecs \2291              if comm=="cyclictest"' >> \2292              /sys/kernel/tracing/events/sched/sched_waking/trigger2293 2294      # echo 'hist:keys=next_pid:\2295              wakeup_lat=common_timestamp.usecs-$ts0:\2296              onmax($wakeup_lat).save(next_comm,prev_pid,prev_prio,prev_comm) \2297              if next_comm=="cyclictest"' >> \2298              /sys/kernel/tracing/events/sched/sched_switch/trigger2299 2300    When the histogram is displayed, the max value and the saved2301    values corresponding to the max are displayed following the rest2302    of the fields::2303 2304      # cat /sys/kernel/tracing/events/sched/sched_switch/hist2305        { next_pid:       2255 } hitcount:        2392306          common_timestamp-ts0:          02307          max:         272308	  next_comm: cyclictest2309          prev_pid:          0  prev_prio:        120  prev_comm: swapper/12310 2311        { next_pid:       2256 } hitcount:       23552312          common_timestamp-ts0: 02313          max:         49  next_comm: cyclictest2314          prev_pid:          0  prev_prio:        120  prev_comm: swapper/02315 2316        Totals:2317            Hits: 129702318            Entries: 22319            Dropped: 02320 2321  - onmax(var).snapshot()2322 2323    The 'onmax(var).snapshot()' hist trigger action is invoked2324    whenever the value of 'var' associated with a histogram entry2325    exceeds the current maximum contained in that variable.2326 2327    The end result is that a global snapshot of the trace buffer will2328    be saved in the tracing/snapshot file if 'var' exceeds the current2329    maximum for any hist trigger entry.2330 2331    Note that in this case the maximum is a global maximum for the2332    current trace instance, which is the maximum across all buckets of2333    the histogram.  The key of the specific trace event that caused2334    the global maximum and the global maximum itself are displayed,2335    along with a message stating that a snapshot has been taken and2336    where to find it.  The user can use the key information displayed2337    to locate the corresponding bucket in the histogram for even more2338    detail.2339 2340    As an example the below defines a couple of hist triggers, one for2341    sched_waking and another for sched_switch, keyed on pid.  Whenever2342    a sched_waking event occurs, the timestamp is saved in the entry2343    corresponding to the current pid, and when the scheduler switches2344    back to that pid, the timestamp difference is calculated.  If the2345    resulting latency, stored in wakeup_lat, exceeds the current2346    maximum latency, a snapshot is taken.  As part of the setup, all2347    the scheduler events are also enabled, which are the events that2348    will show up in the snapshot when it is taken at some point::2349 2350      # echo 1 > /sys/kernel/tracing/events/sched/enable2351 2352      # echo 'hist:keys=pid:ts0=common_timestamp.usecs \2353              if comm=="cyclictest"' >> \2354              /sys/kernel/tracing/events/sched/sched_waking/trigger2355 2356      # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0: \2357              onmax($wakeup_lat).save(next_prio,next_comm,prev_pid,prev_prio, \2358	      prev_comm):onmax($wakeup_lat).snapshot() \2359	      if next_comm=="cyclictest"' >> \2360	      /sys/kernel/tracing/events/sched/sched_switch/trigger2361 2362    When the histogram is displayed, for each bucket the max value2363    and the saved values corresponding to the max are displayed2364    following the rest of the fields.2365 2366    If a snapshot was taken, there is also a message indicating that,2367    along with the value and event that triggered the global maximum::2368 2369      # cat /sys/kernel/tracing/events/sched/sched_switch/hist2370        { next_pid:       2101 } hitcount:        2002371	  max:         52  next_prio:        120  next_comm: cyclictest \2372          prev_pid:          0  prev_prio:        120  prev_comm: swapper/62373 2374        { next_pid:       2103 } hitcount:       13262375	  max:        572  next_prio:         19  next_comm: cyclictest \2376          prev_pid:          0  prev_prio:        120  prev_comm: swapper/12377 2378        { next_pid:       2102 } hitcount:       1982 \2379	  max:         74  next_prio:         19  next_comm: cyclictest \2380          prev_pid:          0  prev_prio:        120  prev_comm: swapper/52381 2382      Snapshot taken (see tracing/snapshot).  Details:2383	  triggering value { onmax($wakeup_lat) }:        572	\2384	  triggered by event with key: { next_pid:       2103 }2385 2386      Totals:2387          Hits: 35082388          Entries: 32389          Dropped: 02390 2391    In the above case, the event that triggered the global maximum has2392    the key with next_pid == 2103.  If you look at the bucket that has2393    2103 as the key, you'll find the additional values save()'d along2394    with the local maximum for that bucket, which should be the same2395    as the global maximum (since that was the same value that2396    triggered the global snapshot).2397 2398    And finally, looking at the snapshot data should show at or near2399    the end the event that triggered the snapshot (in this case you2400    can verify the timestamps between the sched_waking and2401    sched_switch events, which should match the time displayed in the2402    global maximum)::2403 2404     # cat /sys/kernel/tracing/snapshot2405 2406         <...>-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=1202407         <idle>-0     [005] d.h3   309.873611: sched_waking: comm=cyclictest pid=2102 prio=19 target_cpu=0052408         <idle>-0     [005] dNh4   309.873613: sched_wakeup: comm=cyclictest pid=2102 prio=19 target_cpu=0052409         <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=192410         <...>-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=1202411         <idle>-0     [005] d.h3   309.874624: sched_waking: comm=cyclictest pid=2102 prio=19 target_cpu=0052412         <idle>-0     [005] dNh4   309.874626: sched_wakeup: comm=cyclictest pid=2102 prio=19 target_cpu=0052413         <idle>-0     [005] dNh3   309.874628: sched_waking: comm=cyclictest pid=2103 prio=19 target_cpu=0052414         <idle>-0     [005] dNh4   309.874630: sched_wakeup: comm=cyclictest pid=2103 prio=19 target_cpu=0052415         <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=192416         <idle>-0     [004] d.h3   309.874757: sched_waking: comm=gnome-terminal- pid=1699 prio=120 target_cpu=0042417         <idle>-0     [004] dNh4   309.874762: sched_wakeup: comm=gnome-terminal- pid=1699 prio=120 target_cpu=0042418         <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=1202419     gnome-terminal--1699  [004] d.h2   309.874941: sched_stat_runtime: comm=gnome-terminal- pid=1699 runtime=180706 [ns] vruntime=1126870572 [ns]2420         <idle>-0     [003] d.s4   309.874956: sched_waking: comm=rcu_sched pid=9 prio=120 target_cpu=0072421         <idle>-0     [003] d.s5   309.874960: sched_wake_idle_without_ipi: cpu=72422         <idle>-0     [003] d.s5   309.874961: sched_wakeup: comm=rcu_sched pid=9 prio=120 target_cpu=0072423         <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=1202424      rcu_sched-9     [007] d..3   309.874973: sched_stat_runtime: comm=rcu_sched pid=9 runtime=13646 [ns] vruntime=22531430286 [ns]2425      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=1202426          <...>-2102  [005] d..4   309.874994: sched_migrate_task: comm=cyclictest pid=2103 prio=19 orig_cpu=5 dest_cpu=12427          <...>-2102  [005] d..4   309.875185: sched_wake_idle_without_ipi: cpu=12428         <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=192429 2430  - onchange(var).save(field,..	.)2431 2432    The 'onchange(var).save(field,...)' hist trigger action is invoked2433    whenever the value of 'var' associated with a histogram entry2434    changes.2435 2436    The end result is that the trace event fields specified as the2437    onchange.save() params will be saved if 'var' changes for that2438    hist trigger entry.  This allows context from the event that2439    changed the value to be saved for later reference.  When the2440    histogram is displayed, additional fields displaying the saved2441    values will be printed.2442 2443  - onchange(var).snapshot()2444 2445    The 'onchange(var).snapshot()' hist trigger action is invoked2446    whenever the value of 'var' associated with a histogram entry2447    changes.2448 2449    The end result is that a global snapshot of the trace buffer will2450    be saved in the tracing/snapshot file if 'var' changes for any2451    hist trigger entry.2452 2453    Note that in this case the changed value is a global variable2454    associated with current trace instance.  The key of the specific2455    trace event that caused the value to change and the global value2456    itself are displayed, along with a message stating that a snapshot2457    has been taken and where to find it.  The user can use the key2458    information displayed to locate the corresponding bucket in the2459    histogram for even more detail.2460 2461    As an example the below defines a hist trigger on the tcp_probe2462    event, keyed on dport.  Whenever a tcp_probe event occurs, the2463    cwnd field is checked against the current value stored in the2464    $cwnd variable.  If the value has changed, a snapshot is taken.2465    As part of the setup, all the scheduler and tcp events are also2466    enabled, which are the events that will show up in the snapshot2467    when it is taken at some point::2468 2469      # echo 1 > /sys/kernel/tracing/events/sched/enable2470      # echo 1 > /sys/kernel/tracing/events/tcp/enable2471 2472      # echo 'hist:keys=dport:cwnd=snd_cwnd: \2473              onchange($cwnd).save(snd_wnd,srtt,rcv_wnd): \2474	      onchange($cwnd).snapshot()' >> \2475	      /sys/kernel/tracing/events/tcp/tcp_probe/trigger2476 2477    When the histogram is displayed, for each bucket the tracked value2478    and the saved values corresponding to that value are displayed2479    following the rest of the fields.2480 2481    If a snapshot was taken, there is also a message indicating that,2482    along with the value and event that triggered the snapshot::2483 2484      # cat /sys/kernel/tracing/events/tcp/tcp_probe/hist2485 2486      { dport:       1521 } hitcount:          82487	changed:         10  snd_wnd:      35456  srtt:     154262  rcv_wnd:      421122488 2489      { dport:         80 } hitcount:         232490	changed:         10  snd_wnd:      28960  srtt:      19604  rcv_wnd:      293122491 2492      { dport:       9001 } hitcount:        1722493	changed:         10  snd_wnd:      48384  srtt:     260444  rcv_wnd:      551682494 2495      { dport:        443 } hitcount:        2112496	changed:         10  snd_wnd:      26960  srtt:      17379  rcv_wnd:      288002497 2498      Snapshot taken (see tracing/snapshot).  Details:2499 2500          triggering value { onchange($cwnd) }:         102501          triggered by event with key: { dport:         80 }2502 2503      Totals:2504          Hits: 4142505          Entries: 42506          Dropped: 02507 2508    In the above case, the event that triggered the snapshot has the2509    key with dport == 80.  If you look at the bucket that has 80 as2510    the key, you'll find the additional values save()'d along with the2511    changed value for that bucket, which should be the same as the2512    global changed value (since that was the same value that triggered2513    the global snapshot).2514 2515    And finally, looking at the snapshot data should show at or near2516    the end the event that triggered the snapshot::2517 2518      # cat /sys/kernel/tracing/snapshot2519 2520         gnome-shell-1261  [006] dN.3    49.823113: sched_stat_runtime: comm=gnome-shell pid=1261 runtime=49347 [ns] vruntime=1835730389 [ns]2521       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=1202522         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=1202523         kworker/3:2-135   [003] d..3    49.823118: sched_stat_runtime: comm=kworker/3:2 pid=135 runtime=5339 [ns] vruntime=17815800388 [ns]2524         kworker/6:2-387   [006] d..3    49.823120: sched_stat_runtime: comm=kworker/6:2 pid=387 runtime=9594 [ns] vruntime=14589605367 [ns]2525         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=1202526         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=1202527              <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=293122528 25293. User space creating a trigger2530--------------------------------2531 2532Writing into /sys/kernel/tracing/trace_marker writes into the ftrace2533ring buffer. This can also act like an event, by writing into the trigger2534file located in /sys/kernel/tracing/events/ftrace/print/2535 2536Modifying cyclictest to write into the trace_marker file before it sleeps2537and after it wakes up, something like this::2538 2539  static void traceputs(char *str)2540  {2541	/* tracemark_fd is the trace_marker file descriptor */2542	if (tracemark_fd < 0)2543		return;2544	/* write the tracemark message */2545	write(tracemark_fd, str, strlen(str));2546  }2547 2548And later add something like::2549 2550	traceputs("start");2551	clock_nanosleep(...);2552	traceputs("end");2553 2554We can make a histogram from this::2555 2556 # cd /sys/kernel/tracing2557 # echo 'latency u64 lat' > synthetic_events2558 # echo 'hist:keys=common_pid:ts0=common_timestamp.usecs if buf == "start"' > events/ftrace/print/trigger2559 # echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"' >> events/ftrace/print/trigger2560 # echo 'hist:keys=lat,common_pid:sort=lat' > events/synthetic/latency/trigger2561 2562The above created a synthetic event called "latency" and two histograms2563against the trace_marker, one gets triggered when "start" is written into the2564trace_marker file and the other when "end" is written. If the pids match, then2565it will call the "latency" synthetic event with the calculated latency as its2566parameter. Finally, a histogram is added to the latency synthetic event to2567record the calculated latency along with the pid.2568 2569Now running cyclictest with::2570 2571 # ./cyclictest -p80 -d0 -i250 -n -a -t --tracemark -b 10002572 2573 -p80  : run threads at priority 802574 -d0   : have all threads run at the same interval2575 -i250 : start the interval at 250 microseconds (all threads will do this)2576 -n    : sleep with nanosleep2577 -a    : affine all threads to a separate CPU2578 -t    : one thread per available CPU2579 --tracemark : enable trace mark writing2580 -b 1000 : stop if any latency is greater than 1000 microseconds2581 2582Note, the -b 1000 is used just to make --tracemark available.2583 2584Then we can see the histogram created by this with::2585 2586 # cat events/synthetic/latency/hist2587 # event histogram2588 #2589 # trigger info: hist:keys=lat,common_pid:vals=hitcount:sort=lat:size=2048 [active]2590 #2591 2592 { lat:        107, common_pid:       2039 } hitcount:          12593 { lat:        122, common_pid:       2041 } hitcount:          12594 { lat:        166, common_pid:       2039 } hitcount:          12595 { lat:        174, common_pid:       2039 } hitcount:          12596 { lat:        194, common_pid:       2041 } hitcount:          12597 { lat:        196, common_pid:       2036 } hitcount:          12598 { lat:        197, common_pid:       2038 } hitcount:          12599 { lat:        198, common_pid:       2039 } hitcount:          12600 { lat:        199, common_pid:       2039 } hitcount:          12601 { lat:        200, common_pid:       2041 } hitcount:          12602 { lat:        201, common_pid:       2039 } hitcount:          22603 { lat:        202, common_pid:       2038 } hitcount:          12604 { lat:        202, common_pid:       2043 } hitcount:          12605 { lat:        203, common_pid:       2039 } hitcount:          12606 { lat:        203, common_pid:       2036 } hitcount:          12607 { lat:        203, common_pid:       2041 } hitcount:          12608 { lat:        206, common_pid:       2038 } hitcount:          22609 { lat:        207, common_pid:       2039 } hitcount:          12610 { lat:        207, common_pid:       2036 } hitcount:          12611 { lat:        208, common_pid:       2040 } hitcount:          12612 { lat:        209, common_pid:       2043 } hitcount:          12613 { lat:        210, common_pid:       2039 } hitcount:          12614 { lat:        211, common_pid:       2039 } hitcount:          42615 { lat:        212, common_pid:       2043 } hitcount:          12616 { lat:        212, common_pid:       2039 } hitcount:          22617 { lat:        213, common_pid:       2039 } hitcount:          12618 { lat:        214, common_pid:       2038 } hitcount:          12619 { lat:        214, common_pid:       2039 } hitcount:          22620 { lat:        214, common_pid:       2042 } hitcount:          12621 { lat:        215, common_pid:       2039 } hitcount:          12622 { lat:        217, common_pid:       2036 } hitcount:          12623 { lat:        217, common_pid:       2040 } hitcount:          12624 { lat:        217, common_pid:       2039 } hitcount:          12625 { lat:        218, common_pid:       2039 } hitcount:          62626 { lat:        219, common_pid:       2039 } hitcount:          92627 { lat:        220, common_pid:       2039 } hitcount:         112628 { lat:        221, common_pid:       2039 } hitcount:          52629 { lat:        221, common_pid:       2042 } hitcount:          12630 { lat:        222, common_pid:       2039 } hitcount:          72631 { lat:        223, common_pid:       2036 } hitcount:          12632 { lat:        223, common_pid:       2039 } hitcount:          32633 { lat:        224, common_pid:       2039 } hitcount:          42634 { lat:        224, common_pid:       2037 } hitcount:          12635 { lat:        224, common_pid:       2036 } hitcount:          22636 { lat:        225, common_pid:       2039 } hitcount:          52637 { lat:        225, common_pid:       2042 } hitcount:          12638 { lat:        226, common_pid:       2039 } hitcount:          72639 { lat:        226, common_pid:       2036 } hitcount:          42640 { lat:        227, common_pid:       2039 } hitcount:          62641 { lat:        227, common_pid:       2036 } hitcount:         122642 { lat:        227, common_pid:       2043 } hitcount:          12643 { lat:        228, common_pid:       2039 } hitcount:          72644 { lat:        228, common_pid:       2036 } hitcount:         142645 { lat:        229, common_pid:       2039 } hitcount:          92646 { lat:        229, common_pid:       2036 } hitcount:          82647 { lat:        229, common_pid:       2038 } hitcount:          12648 { lat:        230, common_pid:       2039 } hitcount:         112649 { lat:        230, common_pid:       2036 } hitcount:          62650 { lat:        230, common_pid:       2043 } hitcount:          12651 { lat:        230, common_pid:       2042 } hitcount:          22652 { lat:        231, common_pid:       2041 } hitcount:          12653 { lat:        231, common_pid:       2036 } hitcount:          62654 { lat:        231, common_pid:       2043 } hitcount:          12655 { lat:        231, common_pid:       2039 } hitcount:          82656 { lat:        232, common_pid:       2037 } hitcount:          12657 { lat:        232, common_pid:       2039 } hitcount:          62658 { lat:        232, common_pid:       2040 } hitcount:          22659 { lat:        232, common_pid:       2036 } hitcount:          52660 { lat:        232, common_pid:       2043 } hitcount:          12661 { lat:        233, common_pid:       2036 } hitcount:          52662 { lat:        233, common_pid:       2039 } hitcount:         112663 { lat:        234, common_pid:       2039 } hitcount:          42664 { lat:        234, common_pid:       2038 } hitcount:          22665 { lat:        234, common_pid:       2043 } hitcount:          22666 { lat:        234, common_pid:       2036 } hitcount:         112667 { lat:        234, common_pid:       2040 } hitcount:          12668 { lat:        235, common_pid:       2037 } hitcount:          22669 { lat:        235, common_pid:       2036 } hitcount:          82670 { lat:        235, common_pid:       2043 } hitcount:          22671 { lat:        235, common_pid:       2039 } hitcount:          52672 { lat:        235, common_pid:       2042 } hitcount:          22673 { lat:        235, common_pid:       2040 } hitcount:          42674 { lat:        235, common_pid:       2041 } hitcount:          12675 { lat:        236, common_pid:       2036 } hitcount:          72676 { lat:        236, common_pid:       2037 } hitcount:          12677 { lat:        236, common_pid:       2041 } hitcount:          52678 { lat:        236, common_pid:       2039 } hitcount:          32679 { lat:        236, common_pid:       2043 } hitcount:          92680 { lat:        236, common_pid:       2040 } hitcount:          72681 { lat:        237, common_pid:       2037 } hitcount:          12682 { lat:        237, common_pid:       2040 } hitcount:          12683 { lat:        237, common_pid:       2036 } hitcount:          92684 { lat:        237, common_pid:       2039 } hitcount:          32685 { lat:        237, common_pid:       2043 } hitcount:          82686 { lat:        237, common_pid:       2042 } hitcount:          22687 { lat:        237, common_pid:       2041 } hitcount:          22688 { lat:        238, common_pid:       2043 } hitcount:         102689 { lat:        238, common_pid:       2040 } hitcount:          12690 { lat:        238, common_pid:       2037 } hitcount:          92691 { lat:        238, common_pid:       2038 } hitcount:          12692 { lat:        238, common_pid:       2039 } hitcount:          12693 { lat:        238, common_pid:       2042 } hitcount:          32694 { lat:        238, common_pid:       2036 } hitcount:          72695 { lat:        239, common_pid:       2041 } hitcount:          12696 { lat:        239, common_pid:       2043 } hitcount:         112697 { lat:        239, common_pid:       2037 } hitcount:         112698 { lat:        239, common_pid:       2038 } hitcount:          62699 { lat:        239, common_pid:       2036 } hitcount:          72700 { lat:        239, common_pid:       2040 } hitcount:          12701 { lat:        239, common_pid:       2042 } hitcount:          92702 { lat:        240, common_pid:       2037 } hitcount:         292703 { lat:        240, common_pid:       2043 } hitcount:         152704 { lat:        240, common_pid:       2040 } hitcount:         442705 { lat:        240, common_pid:       2039 } hitcount:          12706 { lat:        240, common_pid:       2041 } hitcount:          22707 { lat:        240, common_pid:       2038 } hitcount:          12708 { lat:        240, common_pid:       2036 } hitcount:         102709 { lat:        240, common_pid:       2042 } hitcount:         132710 { lat:        241, common_pid:       2036 } hitcount:         212711 { lat:        241, common_pid:       2041 } hitcount:         362712 { lat:        241, common_pid:       2037 } hitcount:         342713 { lat:        241, common_pid:       2042 } hitcount:         142714 { lat:        241, common_pid:       2040 } hitcount:         942715 { lat:        241, common_pid:       2039 } hitcount:         122716 { lat:        241, common_pid:       2038 } hitcount:          22717 { lat:        241, common_pid:       2043 } hitcount:         282718 { lat:        242, common_pid:       2040 } hitcount:        1092719 { lat:        242, common_pid:       2041 } hitcount:        5062720 { lat:        242, common_pid:       2039 } hitcount:        1552721 { lat:        242, common_pid:       2042 } hitcount:         212722 { lat:        242, common_pid:       2037 } hitcount:         522723 { lat:        242, common_pid:       2043 } hitcount:         212724 { lat:        242, common_pid:       2036 } hitcount:         162725 { lat:        242, common_pid:       2038 } hitcount:        1562726 { lat:        243, common_pid:       2037 } hitcount:         462727 { lat:        243, common_pid:       2039 } hitcount:         402728 { lat:        243, common_pid:       2042 } hitcount:        1192729 { lat:        243, common_pid:       2041 } hitcount:        6112730 { lat:        243, common_pid:       2036 } hitcount:         692731 { lat:        243, common_pid:       2038 } hitcount:        7842732 { lat:        243, common_pid:       2040 } hitcount:        3232733 { lat:        243, common_pid:       2043 } hitcount:         142734 { lat:        244, common_pid:       2043 } hitcount:         352735 { lat:        244, common_pid:       2042 } hitcount:        3052736 { lat:        244, common_pid:       2039 } hitcount:          82737 { lat:        244, common_pid:       2040 } hitcount:       45152738 { lat:        244, common_pid:       2038 } hitcount:        3712739 { lat:        244, common_pid:       2037 } hitcount:         312740 { lat:        244, common_pid:       2036 } hitcount:        1142741 { lat:        244, common_pid:       2041 } hitcount:       33962742 { lat:        245, common_pid:       2036 } hitcount:        7002743 { lat:        245, common_pid:       2041 } hitcount:       27722744 { lat:        245, common_pid:       2037 } hitcount:        2682745 { lat:        245, common_pid:       2039 } hitcount:        4722746 { lat:        245, common_pid:       2038 } hitcount:       27582747 { lat:        245, common_pid:       2042 } hitcount:       38332748 { lat:        245, common_pid:       2040 } hitcount:       31052749 { lat:        245, common_pid:       2043 } hitcount:        6452750 { lat:        246, common_pid:       2038 } hitcount:       34512751 { lat:        246, common_pid:       2041 } hitcount:        1422752 { lat:        246, common_pid:       2037 } hitcount:       51012753 { lat:        246, common_pid:       2040 } hitcount:         682754 { lat:        246, common_pid:       2043 } hitcount:       50992755 { lat:        246, common_pid:       2039 } hitcount:       56082756 { lat:        246, common_pid:       2042 } hitcount:       37232757 { lat:        246, common_pid:       2036 } hitcount:       47382758 { lat:        247, common_pid:       2042 } hitcount:        3122759 { lat:        247, common_pid:       2043 } hitcount:       23852760 { lat:        247, common_pid:       2041 } hitcount:        4522761 { lat:        247, common_pid:       2038 } hitcount:        7922762 { lat:        247, common_pid:       2040 } hitcount:         782763 { lat:        247, common_pid:       2036 } hitcount:       23752764 { lat:        247, common_pid:       2039 } hitcount:       18342765 { lat:        247, common_pid:       2037 } hitcount:       26552766 { lat:        248, common_pid:       2037 } hitcount:         362767 { lat:        248, common_pid:       2042 } hitcount:         112768 { lat:        248, common_pid:       2038 } hitcount:        1222769 { lat:        248, common_pid:       2036 } hitcount:        1352770 { lat:        248, common_pid:       2039 } hitcount:         262771 { lat:        248, common_pid:       2041 } hitcount:        5032772 { lat:        248, common_pid:       2043 } hitcount:         662773 { lat:        248, common_pid:       2040 } hitcount:         462774 { lat:        249, common_pid:       2037 } hitcount:         292775 { lat:        249, common_pid:       2038 } hitcount:          12776 { lat:        249, common_pid:       2043 } hitcount:         292777 { lat:        249, common_pid:       2039 } hitcount:          82778 { lat:        249, common_pid:       2042 } hitcount:         562779 { lat:        249, common_pid:       2040 } hitcount:         272780 { lat:        249, common_pid:       2041 } hitcount:         112781 { lat:        249, common_pid:       2036 } hitcount:         272782 { lat:        250, common_pid:       2038 } hitcount:          12783 { lat:        250, common_pid:       2036 } hitcount:         302784 { lat:        250, common_pid:       2040 } hitcount:         192785 { lat:        250, common_pid:       2043 } hitcount:         222786 { lat:        250, common_pid:       2042 } hitcount:         202787 { lat:        250, common_pid:       2041 } hitcount:          12788 { lat:        250, common_pid:       2039 } hitcount:          62789 { lat:        250, common_pid:       2037 } hitcount:         482790 { lat:        251, common_pid:       2037 } hitcount:         432791 { lat:        251, common_pid:       2039 } hitcount:          12792 { lat:        251, common_pid:       2036 } hitcount:         122793 { lat:        251, common_pid:       2042 } hitcount:          22794 { lat:        251, common_pid:       2041 } hitcount:          12795 { lat:        251, common_pid:       2043 } hitcount:         152796 { lat:        251, common_pid:       2040 } hitcount:          32797 { lat:        252, common_pid:       2040 } hitcount:          12798 { lat:        252, common_pid:       2036 } hitcount:         122799 { lat:        252, common_pid:       2037 } hitcount:         212800 { lat:        252, common_pid:       2043 } hitcount:         142801 { lat:        253, common_pid:       2037 } hitcount:         212802 { lat:        253, common_pid:       2039 } hitcount:          22803 { lat:        253, common_pid:       2036 } hitcount:          92804 { lat:        253, common_pid:       2043 } hitcount:          62805 { lat:        253, common_pid:       2040 } hitcount:          12806 { lat:        254, common_pid:       2036 } hitcount:          82807 { lat:        254, common_pid:       2043 } hitcount:          32808 { lat:        254, common_pid:       2041 } hitcount:          12809 { lat:        254, common_pid:       2042 } hitcount:          12810 { lat:        254, common_pid:       2039 } hitcount:          12811 { lat:        254, common_pid:       2037 } hitcount:         122812 { lat:        255, common_pid:       2043 } hitcount:          12813 { lat:        255, common_pid:       2037 } hitcount:          22814 { lat:        255, common_pid:       2036 } hitcount:          22815 { lat:        255, common_pid:       2039 } hitcount:          82816 { lat:        256, common_pid:       2043 } hitcount:          12817 { lat:        256, common_pid:       2036 } hitcount:          42818 { lat:        256, common_pid:       2039 } hitcount:          62819 { lat:        257, common_pid:       2039 } hitcount:          52820 { lat:        257, common_pid:       2036 } hitcount:          42821 { lat:        258, common_pid:       2039 } hitcount:          52822 { lat:        258, common_pid:       2036 } hitcount:          22823 { lat:        259, common_pid:       2036 } hitcount:          72824 { lat:        259, common_pid:       2039 } hitcount:          72825 { lat:        260, common_pid:       2036 } hitcount:          82826 { lat:        260, common_pid:       2039 } hitcount:          62827 { lat:        261, common_pid:       2036 } hitcount:          52828 { lat:        261, common_pid:       2039 } hitcount:          72829 { lat:        262, common_pid:       2039 } hitcount:          52830 { lat:        262, common_pid:       2036 } hitcount:          52831 { lat:        263, common_pid:       2039 } hitcount:          72832 { lat:        263, common_pid:       2036 } hitcount:          72833 { lat:        264, common_pid:       2039 } hitcount:          92834 { lat:        264, common_pid:       2036 } hitcount:          92835 { lat:        265, common_pid:       2036 } hitcount:          52836 { lat:        265, common_pid:       2039 } hitcount:          12837 { lat:        266, common_pid:       2036 } hitcount:          12838 { lat:        266, common_pid:       2039 } hitcount:          32839 { lat:        267, common_pid:       2036 } hitcount:          12840 { lat:        267, common_pid:       2039 } hitcount:          32841 { lat:        268, common_pid:       2036 } hitcount:          12842 { lat:        268, common_pid:       2039 } hitcount:          62843 { lat:        269, common_pid:       2036 } hitcount:          12844 { lat:        269, common_pid:       2043 } hitcount:          12845 { lat:        269, common_pid:       2039 } hitcount:          22846 { lat:        270, common_pid:       2040 } hitcount:          12847 { lat:        270, common_pid:       2039 } hitcount:          62848 { lat:        271, common_pid:       2041 } hitcount:          12849 { lat:        271, common_pid:       2039 } hitcount:          52850 { lat:        272, common_pid:       2039 } hitcount:         102851 { lat:        273, common_pid:       2039 } hitcount:          82852 { lat:        274, common_pid:       2039 } hitcount:          22853 { lat:        275, common_pid:       2039 } hitcount:          12854 { lat:        276, common_pid:       2039 } hitcount:          22855 { lat:        276, common_pid:       2037 } hitcount:          12856 { lat:        276, common_pid:       2038 } hitcount:          12857 { lat:        277, common_pid:       2039 } hitcount:          12858 { lat:        277, common_pid:       2042 } hitcount:          12859 { lat:        278, common_pid:       2039 } hitcount:          12860 { lat:        279, common_pid:       2039 } hitcount:          42861 { lat:        279, common_pid:       2043 } hitcount:          12862 { lat:        280, common_pid:       2039 } hitcount:          32863 { lat:        283, common_pid:       2036 } hitcount:          22864 { lat:        284, common_pid:       2039 } hitcount:          12865 { lat:        284, common_pid:       2043 } hitcount:          12866 { lat:        288, common_pid:       2039 } hitcount:          12867 { lat:        289, common_pid:       2039 } hitcount:          12868 { lat:        300, common_pid:       2039 } hitcount:          12869 { lat:        384, common_pid:       2039 } hitcount:          12870 2871 Totals:2872     Hits: 676252873     Entries: 2782874     Dropped: 02875 2876Note, the writes are around the sleep, so ideally they will all be of 2502877microseconds. If you are wondering how there are several that are under2878250 microseconds, that is because the way cyclictest works, is if one2879iteration comes in late, the next one will set the timer to wake up less that2880250. That is, if an iteration came in 50 microseconds late, the next wake up2881will be at 200 microseconds.2882 2883But this could easily be done in userspace. To make this even more2884interesting, we can mix the histogram between events that happened in the2885kernel with trace_marker::2886 2887 # cd /sys/kernel/tracing2888 # echo 'latency u64 lat' > synthetic_events2889 # echo 'hist:keys=pid:ts0=common_timestamp.usecs' > events/sched/sched_waking/trigger2890 # echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat) if buf == "end"' > events/ftrace/print/trigger2891 # echo 'hist:keys=lat,common_pid:sort=lat' > events/synthetic/latency/trigger2892 2893The difference this time is that instead of using the trace_marker to start2894the latency, the sched_waking event is used, matching the common_pid for the2895trace_marker write with the pid that is being woken by sched_waking.2896 2897After running cyclictest again with the same parameters, we now have::2898 2899 # cat events/synthetic/latency/hist2900 # event histogram2901 #2902 # trigger info: hist:keys=lat,common_pid:vals=hitcount:sort=lat:size=2048 [active]2903 #2904 2905 { lat:          7, common_pid:       2302 } hitcount:        6402906 { lat:          7, common_pid:       2299 } hitcount:         422907 { lat:          7, common_pid:       2303 } hitcount:         182908 { lat:          7, common_pid:       2305 } hitcount:        1662909 { lat:          7, common_pid:       2306 } hitcount:          12910 { lat:          7, common_pid:       2301 } hitcount:         912911 { lat:          7, common_pid:       2300 } hitcount:         172912 { lat:          8, common_pid:       2303 } hitcount:       82962913 { lat:          8, common_pid:       2304 } hitcount:       68642914 { lat:          8, common_pid:       2305 } hitcount:       94642915 { lat:          8, common_pid:       2301 } hitcount:       92132916 { lat:          8, common_pid:       2306 } hitcount:       62462917 { lat:          8, common_pid:       2302 } hitcount:       87972918 { lat:          8, common_pid:       2299 } hitcount:       87712919 { lat:          8, common_pid:       2300 } hitcount:       81192920 { lat:          9, common_pid:       2305 } hitcount:       15192921 { lat:          9, common_pid:       2299 } hitcount:       23462922 { lat:          9, common_pid:       2303 } hitcount:       28412923 { lat:          9, common_pid:       2301 } hitcount:       18462924 { lat:          9, common_pid:       2304 } hitcount:       38612925 { lat:          9, common_pid:       2302 } hitcount:       12102926 { lat:          9, common_pid:       2300 } hitcount:       27622927 { lat:          9, common_pid:       2306 } hitcount:       42472928 { lat:         10, common_pid:       2299 } hitcount:         162929 { lat:         10, common_pid:       2306 } hitcount:        3332930 { lat:         10, common_pid:       2303 } hitcount:         162931 { lat:         10, common_pid:       2304 } hitcount:        1682932 { lat:         10, common_pid:       2302 } hitcount:        2402933 { lat:         10, common_pid:       2301 } hitcount:         282934 { lat:         10, common_pid:       2300 } hitcount:         952935 { lat:         10, common_pid:       2305 } hitcount:         182936 { lat:         11, common_pid:       2303 } hitcount:          52937 { lat:         11, common_pid:       2305 } hitcount:          82938 { lat:         11, common_pid:       2306 } hitcount:        2212939 { lat:         11, common_pid:       2302 } hitcount:         762940 { lat:         11, common_pid:       2304 } hitcount:         262941 { lat:         11, common_pid:       2300 } hitcount:        1252942 { lat:         11, common_pid:       2299 } hitcount:          22943 { lat:         12, common_pid:       2305 } hitcount:          32944 { lat:         12, common_pid:       2300 } hitcount:          62945 { lat:         12, common_pid:       2306 } hitcount:         902946 { lat:         12, common_pid:       2302 } hitcount:          42947 { lat:         12, common_pid:       2303 } hitcount:          12948 { lat:         12, common_pid:       2304 } hitcount:        1222949 { lat:         13, common_pid:       2300 } hitcount:         122950 { lat:         13, common_pid:       2301 } hitcount:          12951 { lat:         13, common_pid:       2306 } hitcount:         322952 { lat:         13, common_pid:       2302 } hitcount:          52953 { lat:         13, common_pid:       2305 } hitcount:          12954 { lat:         13, common_pid:       2303 } hitcount:          12955 { lat:         13, common_pid:       2304 } hitcount:         612956 { lat:         14, common_pid:       2303 } hitcount:          42957 { lat:         14, common_pid:       2306 } hitcount:          52958 { lat:         14, common_pid:       2305 } hitcount:          42959 { lat:         14, common_pid:       2304 } hitcount:         622960 { lat:         14, common_pid:       2302 } hitcount:         192961 { lat:         14, common_pid:       2300 } hitcount:         332962 { lat:         14, common_pid:       2299 } hitcount:          12963 { lat:         14, common_pid:       2301 } hitcount:          42964 { lat:         15, common_pid:       2305 } hitcount:          12965 { lat:         15, common_pid:       2302 } hitcount:         252966 { lat:         15, common_pid:       2300 } hitcount:         112967 { lat:         15, common_pid:       2299 } hitcount:          52968 { lat:         15, common_pid:       2301 } hitcount:          12969 { lat:         15, common_pid:       2304 } hitcount:          82970 { lat:         15, common_pid:       2303 } hitcount:          12971 { lat:         15, common_pid:       2306 } hitcount:          62972 { lat:         16, common_pid:       2302 } hitcount:         312973 { lat:         16, common_pid:       2306 } hitcount:          32974 { lat:         16, common_pid:       2300 } hitcount:          52975 { lat:         17, common_pid:       2302 } hitcount:          62976 { lat:         17, common_pid:       2303 } hitcount:          12977 { lat:         18, common_pid:       2304 } hitcount:          12978 { lat:         18, common_pid:       2302 } hitcount:          82979 { lat:         18, common_pid:       2299 } hitcount:          12980 { lat:         18, common_pid:       2301 } hitcount:          12981 { lat:         19, common_pid:       2303 } hitcount:          42982 { lat:         19, common_pid:       2304 } hitcount:          52983 { lat:         19, common_pid:       2302 } hitcount:          42984 { lat:         19, common_pid:       2299 } hitcount:          32985 { lat:         19, common_pid:       2306 } hitcount:          12986 { lat:         19, common_pid:       2300 } hitcount:          42987 { lat:         19, common_pid:       2305 } hitcount:          52988 { lat:         20, common_pid:       2299 } hitcount:          22989 { lat:         20, common_pid:       2302 } hitcount:          32990 { lat:         20, common_pid:       2305 } hitcount:          12991 { lat:         20, common_pid:       2300 } hitcount:          22992 { lat:         20, common_pid:       2301 } hitcount:          22993 { lat:         20, common_pid:       2303 } hitcount:          32994 { lat:         21, common_pid:       2305 } hitcount:          12995 { lat:         21, common_pid:       2299 } hitcount:          52996 { lat:         21, common_pid:       2303 } hitcount:          42997 { lat:         21, common_pid:       2302 } hitcount:          72998 { lat:         21, common_pid:       2300 } hitcount:          12999 { lat:         21, common_pid:       2301 } hitcount:          53000 { lat:         21, common_pid:       2304 } hitcount:          23001 { lat:         22, common_pid:       2302 } hitcount:          53002 { lat:         22, common_pid:       2303 } hitcount:          13003 { lat:         22, common_pid:       2306 } hitcount:          33004 { lat:         22, common_pid:       2301 } hitcount:          23005 { lat:         22, common_pid:       2300 } hitcount:          13006 { lat:         22, common_pid:       2299 } hitcount:          13007 { lat:         22, common_pid:       2305 } hitcount:          13008 { lat:         22, common_pid:       2304 } hitcount:          13009 { lat:         23, common_pid:       2299 } hitcount:          13010 { lat:         23, common_pid:       2306 } hitcount:          23011 { lat:         23, common_pid:       2302 } hitcount:          63012 { lat:         24, common_pid:       2302 } hitcount:          33013 { lat:         24, common_pid:       2300 } hitcount:          13014 { lat:         24, common_pid:       2306 } hitcount:          23015 { lat:         24, common_pid:       2305 } hitcount:          13016 { lat:         24, common_pid:       2299 } hitcount:          13017 { lat:         25, common_pid:       2300 } hitcount:          13018 { lat:         25, common_pid:       2302 } hitcount:          43019 { lat:         26, common_pid:       2302 } hitcount:          23020 { lat:         27, common_pid:       2305 } hitcount:          13021 { lat:         27, common_pid:       2300 } hitcount:          13022 { lat:         27, common_pid:       2302 } hitcount:          33023 { lat:         28, common_pid:       2306 } hitcount:          13024 { lat:         28, common_pid:       2302 } hitcount:          43025 { lat:         29, common_pid:       2302 } hitcount:          13026 { lat:         29, common_pid:       2300 } hitcount:          23027 { lat:         29, common_pid:       2306 } hitcount:          13028 { lat:         29, common_pid:       2304 } hitcount:          13029 { lat:         30, common_pid:       2302 } hitcount:          43030 { lat:         31, common_pid:       2302 } hitcount:          63031 { lat:         32, common_pid:       2302 } hitcount:          13032 { lat:         33, common_pid:       2299 } hitcount:          13033 { lat:         33, common_pid:       2302 } hitcount:          33034 { lat:         34, common_pid:       2302 } hitcount:          23035 { lat:         35, common_pid:       2302 } hitcount:          13036 { lat:         35, common_pid:       2304 } hitcount:          13037 { lat:         36, common_pid:       2302 } hitcount:          43038 { lat:         37, common_pid:       2302 } hitcount:          63039 { lat:         38, common_pid:       2302 } hitcount:          23040 { lat:         39, common_pid:       2302 } hitcount:          23041 { lat:         39, common_pid:       2304 } hitcount:          13042 { lat:         40, common_pid:       2304 } hitcount:          23043 { lat:         40, common_pid:       2302 } hitcount:          53044 { lat:         41, common_pid:       2304 } hitcount:          13045 { lat:         41, common_pid:       2302 } hitcount:          83046 { lat:         42, common_pid:       2302 } hitcount:          63047 { lat:         42, common_pid:       2304 } hitcount:          13048 { lat:         43, common_pid:       2302 } hitcount:          33049 { lat:         43, common_pid:       2304 } hitcount:          43050 { lat:         44, common_pid:       2302 } hitcount:          63051 { lat:         45, common_pid:       2302 } hitcount:          53052 { lat:         46, common_pid:       2302 } hitcount:          53053 { lat:         47, common_pid:       2302 } hitcount:          73054 { lat:         48, common_pid:       2301 } hitcount:          13055 { lat:         48, common_pid:       2302 } hitcount:          93056 { lat:         49, common_pid:       2302 } hitcount:          33057 { lat:         50, common_pid:       2302 } hitcount:          13058 { lat:         50, common_pid:       2301 } hitcount:          13059 { lat:         51, common_pid:       2302 } hitcount:          23060 { lat:         51, common_pid:       2301 } hitcount:          13061 { lat:         61, common_pid:       2302 } hitcount:          13062 { lat:        110, common_pid:       2302 } hitcount:          13063 3064 Totals:3065     Hits: 895653066     Entries: 1583067     Dropped: 03068 3069This doesn't tell us any information about how late cyclictest may have3070woken up, but it does show us a nice histogram of how long it took from3071the time that cyclictest was woken to the time it made it into user space.3072