events.txt 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070
  1. Event Tracing
  2. Documentation written by Theodore Ts'o
  3. Updated by Li Zefan and Tom Zanussi
  4. 1. Introduction
  5. ===============
  6. Tracepoints (see Documentation/trace/tracepoints.txt) can be used
  7. without creating custom kernel modules to register probe functions
  8. using the event tracing infrastructure.
  9. Not all tracepoints can be traced using the event tracing system;
  10. the kernel developer must provide code snippets which define how the
  11. tracing information is saved into the tracing buffer, and how the
  12. tracing information should be printed.
  13. 2. Using Event Tracing
  14. ======================
  15. 2.1 Via the 'set_event' interface
  16. ---------------------------------
  17. The events which are available for tracing can be found in the file
  18. /sys/kernel/debug/tracing/available_events.
  19. To enable a particular event, such as 'sched_wakeup', simply echo it
  20. to /sys/kernel/debug/tracing/set_event. For example:
  21. # echo sched_wakeup >> /sys/kernel/debug/tracing/set_event
  22. [ Note: '>>' is necessary, otherwise it will firstly disable
  23. all the events. ]
  24. To disable an event, echo the event name to the set_event file prefixed
  25. with an exclamation point:
  26. # echo '!sched_wakeup' >> /sys/kernel/debug/tracing/set_event
  27. To disable all events, echo an empty line to the set_event file:
  28. # echo > /sys/kernel/debug/tracing/set_event
  29. To enable all events, echo '*:*' or '*:' to the set_event file:
  30. # echo *:* > /sys/kernel/debug/tracing/set_event
  31. The events are organized into subsystems, such as ext4, irq, sched,
  32. etc., and a full event name looks like this: <subsystem>:<event>. The
  33. subsystem name is optional, but it is displayed in the available_events
  34. file. All of the events in a subsystem can be specified via the syntax
  35. "<subsystem>:*"; for example, to enable all irq events, you can use the
  36. command:
  37. # echo 'irq:*' > /sys/kernel/debug/tracing/set_event
  38. 2.2 Via the 'enable' toggle
  39. ---------------------------
  40. The events available are also listed in /sys/kernel/debug/tracing/events/ hierarchy
  41. of directories.
  42. To enable event 'sched_wakeup':
  43. # echo 1 > /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
  44. To disable it:
  45. # echo 0 > /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
  46. To enable all events in sched subsystem:
  47. # echo 1 > /sys/kernel/debug/tracing/events/sched/enable
  48. To enable all events:
  49. # echo 1 > /sys/kernel/debug/tracing/events/enable
  50. When reading one of these enable files, there are four results:
  51. 0 - all events this file affects are disabled
  52. 1 - all events this file affects are enabled
  53. X - there is a mixture of events enabled and disabled
  54. ? - this file does not affect any event
  55. 2.3 Boot option
  56. ---------------
  57. In order to facilitate early boot debugging, use boot option:
  58. trace_event=[event-list]
  59. event-list is a comma separated list of events. See section 2.1 for event
  60. format.
  61. 3. Defining an event-enabled tracepoint
  62. =======================================
  63. See The example provided in samples/trace_events
  64. 4. Event formats
  65. ================
  66. Each trace event has a 'format' file associated with it that contains
  67. a description of each field in a logged event. This information can
  68. be used to parse the binary trace stream, and is also the place to
  69. find the field names that can be used in event filters (see section 5).
  70. It also displays the format string that will be used to print the
  71. event in text mode, along with the event name and ID used for
  72. profiling.
  73. Every event has a set of 'common' fields associated with it; these are
  74. the fields prefixed with 'common_'. The other fields vary between
  75. events and correspond to the fields defined in the TRACE_EVENT
  76. definition for that event.
  77. Each field in the format has the form:
  78. field:field-type field-name; offset:N; size:N;
  79. where offset is the offset of the field in the trace record and size
  80. is the size of the data item, in bytes.
  81. For example, here's the information displayed for the 'sched_wakeup'
  82. event:
  83. # cat /sys/kernel/debug/tracing/events/sched/sched_wakeup/format
  84. name: sched_wakeup
  85. ID: 60
  86. format:
  87. field:unsigned short common_type; offset:0; size:2;
  88. field:unsigned char common_flags; offset:2; size:1;
  89. field:unsigned char common_preempt_count; offset:3; size:1;
  90. field:int common_pid; offset:4; size:4;
  91. field:int common_tgid; offset:8; size:4;
  92. field:char comm[TASK_COMM_LEN]; offset:12; size:16;
  93. field:pid_t pid; offset:28; size:4;
  94. field:int prio; offset:32; size:4;
  95. field:int success; offset:36; size:4;
  96. field:int cpu; offset:40; size:4;
  97. print fmt: "task %s:%d [%d] success=%d [%03d]", REC->comm, REC->pid,
  98. REC->prio, REC->success, REC->cpu
  99. This event contains 10 fields, the first 5 common and the remaining 5
  100. event-specific. All the fields for this event are numeric, except for
  101. 'comm' which is a string, a distinction important for event filtering.
  102. 5. Event filtering
  103. ==================
  104. Trace events can be filtered in the kernel by associating boolean
  105. 'filter expressions' with them. As soon as an event is logged into
  106. the trace buffer, its fields are checked against the filter expression
  107. associated with that event type. An event with field values that
  108. 'match' the filter will appear in the trace output, and an event whose
  109. values don't match will be discarded. An event with no filter
  110. associated with it matches everything, and is the default when no
  111. filter has been set for an event.
  112. 5.1 Expression syntax
  113. ---------------------
  114. A filter expression consists of one or more 'predicates' that can be
  115. combined using the logical operators '&&' and '||'. A predicate is
  116. simply a clause that compares the value of a field contained within a
  117. logged event with a constant value and returns either 0 or 1 depending
  118. on whether the field value matched (1) or didn't match (0):
  119. field-name relational-operator value
  120. Parentheses can be used to provide arbitrary logical groupings and
  121. double-quotes can be used to prevent the shell from interpreting
  122. operators as shell metacharacters.
  123. The field-names available for use in filters can be found in the
  124. 'format' files for trace events (see section 4).
  125. The relational-operators depend on the type of the field being tested:
  126. The operators available for numeric fields are:
  127. ==, !=, <, <=, >, >=, &
  128. And for string fields they are:
  129. ==, !=, ~
  130. The glob (~) only accepts a wild card character (*) at the start and or
  131. end of the string. For example:
  132. prev_comm ~ "*sh"
  133. prev_comm ~ "sh*"
  134. prev_comm ~ "*sh*"
  135. But does not allow for it to be within the string:
  136. prev_comm ~ "ba*sh" <-- is invalid
  137. 5.2 Setting filters
  138. -------------------
  139. A filter for an individual event is set by writing a filter expression
  140. to the 'filter' file for the given event.
  141. For example:
  142. # cd /sys/kernel/debug/tracing/events/sched/sched_wakeup
  143. # echo "common_preempt_count > 4" > filter
  144. A slightly more involved example:
  145. # cd /sys/kernel/debug/tracing/events/signal/signal_generate
  146. # echo "((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
  147. If there is an error in the expression, you'll get an 'Invalid
  148. argument' error when setting it, and the erroneous string along with
  149. an error message can be seen by looking at the filter e.g.:
  150. # cd /sys/kernel/debug/tracing/events/signal/signal_generate
  151. # echo "((sig >= 10 && sig < 15) || dsig == 17) && comm != bash" > filter
  152. -bash: echo: write error: Invalid argument
  153. # cat filter
  154. ((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
  155. ^
  156. parse_error: Field not found
  157. Currently the caret ('^') for an error always appears at the beginning of
  158. the filter string; the error message should still be useful though
  159. even without more accurate position info.
  160. 5.3 Clearing filters
  161. --------------------
  162. To clear the filter for an event, write a '0' to the event's filter
  163. file.
  164. To clear the filters for all events in a subsystem, write a '0' to the
  165. subsystem's filter file.
  166. 5.3 Subsystem filters
  167. ---------------------
  168. For convenience, filters for every event in a subsystem can be set or
  169. cleared as a group by writing a filter expression into the filter file
  170. at the root of the subsystem. Note however, that if a filter for any
  171. event within the subsystem lacks a field specified in the subsystem
  172. filter, or if the filter can't be applied for any other reason, the
  173. filter for that event will retain its previous setting. This can
  174. result in an unintended mixture of filters which could lead to
  175. confusing (to the user who might think different filters are in
  176. effect) trace output. Only filters that reference just the common
  177. fields can be guaranteed to propagate successfully to all events.
  178. Here are a few subsystem filter examples that also illustrate the
  179. above points:
  180. Clear the filters on all events in the sched subsystem:
  181. # cd /sys/kernel/debug/tracing/events/sched
  182. # echo 0 > filter
  183. # cat sched_switch/filter
  184. none
  185. # cat sched_wakeup/filter
  186. none
  187. Set a filter using only common fields for all events in the sched
  188. subsystem (all events end up with the same filter):
  189. # cd /sys/kernel/debug/tracing/events/sched
  190. # echo common_pid == 0 > filter
  191. # cat sched_switch/filter
  192. common_pid == 0
  193. # cat sched_wakeup/filter
  194. common_pid == 0
  195. Attempt to set a filter using a non-common field for all events in the
  196. sched subsystem (all events but those that have a prev_pid field retain
  197. their old filters):
  198. # cd /sys/kernel/debug/tracing/events/sched
  199. # echo prev_pid == 0 > filter
  200. # cat sched_switch/filter
  201. prev_pid == 0
  202. # cat sched_wakeup/filter
  203. common_pid == 0
  204. 5.4 PID filtering
  205. -----------------
  206. The set_event_pid file in the same directory as the top events directory
  207. exists, will filter all events from tracing any task that does not have the
  208. PID listed in the set_event_pid file.
  209. # cd /sys/kernel/debug/tracing
  210. # echo $$ > set_event_pid
  211. # echo 1 > events/enabled
  212. Will only trace events for the current task.
  213. To add more PIDs without losing the PIDs already included, use '>>'.
  214. # echo 123 244 1 >> set_event_pid
  215. 6. Event triggers
  216. =================
  217. Trace events can be made to conditionally invoke trigger 'commands'
  218. which can take various forms and are described in detail below;
  219. examples would be enabling or disabling other trace events or invoking
  220. a stack trace whenever the trace event is hit. Whenever a trace event
  221. with attached triggers is invoked, the set of trigger commands
  222. associated with that event is invoked. Any given trigger can
  223. additionally have an event filter of the same form as described in
  224. section 5 (Event filtering) associated with it - the command will only
  225. be invoked if the event being invoked passes the associated filter.
  226. If no filter is associated with the trigger, it always passes.
  227. Triggers are added to and removed from a particular event by writing
  228. trigger expressions to the 'trigger' file for the given event.
  229. A given event can have any number of triggers associated with it,
  230. subject to any restrictions that individual commands may have in that
  231. regard.
  232. Event triggers are implemented on top of "soft" mode, which means that
  233. whenever a trace event has one or more triggers associated with it,
  234. the event is activated even if it isn't actually enabled, but is
  235. disabled in a "soft" mode. That is, the tracepoint will be called,
  236. but just will not be traced, unless of course it's actually enabled.
  237. This scheme allows triggers to be invoked even for events that aren't
  238. enabled, and also allows the current event filter implementation to be
  239. used for conditionally invoking triggers.
  240. The syntax for event triggers is roughly based on the syntax for
  241. set_ftrace_filter 'ftrace filter commands' (see the 'Filter commands'
  242. section of Documentation/trace/ftrace.txt), but there are major
  243. differences and the implementation isn't currently tied to it in any
  244. way, so beware about making generalizations between the two.
  245. 6.1 Expression syntax
  246. ---------------------
  247. Triggers are added by echoing the command to the 'trigger' file:
  248. # echo 'command[:count] [if filter]' > trigger
  249. Triggers are removed by echoing the same command but starting with '!'
  250. to the 'trigger' file:
  251. # echo '!command[:count] [if filter]' > trigger
  252. The [if filter] part isn't used in matching commands when removing, so
  253. leaving that off in a '!' command will accomplish the same thing as
  254. having it in.
  255. The filter syntax is the same as that described in the 'Event
  256. filtering' section above.
  257. For ease of use, writing to the trigger file using '>' currently just
  258. adds or removes a single trigger and there's no explicit '>>' support
  259. ('>' actually behaves like '>>') or truncation support to remove all
  260. triggers (you have to use '!' for each one added.)
  261. 6.2 Supported trigger commands
  262. ------------------------------
  263. The following commands are supported:
  264. - enable_event/disable_event
  265. These commands can enable or disable another trace event whenever
  266. the triggering event is hit. When these commands are registered,
  267. the other trace event is activated, but disabled in a "soft" mode.
  268. That is, the tracepoint will be called, but just will not be traced.
  269. The event tracepoint stays in this mode as long as there's a trigger
  270. in effect that can trigger it.
  271. For example, the following trigger causes kmalloc events to be
  272. traced when a read system call is entered, and the :1 at the end
  273. specifies that this enablement happens only once:
  274. # echo 'enable_event:kmem:kmalloc:1' > \
  275. /sys/kernel/debug/tracing/events/syscalls/sys_enter_read/trigger
  276. The following trigger causes kmalloc events to stop being traced
  277. when a read system call exits. This disablement happens on every
  278. read system call exit:
  279. # echo 'disable_event:kmem:kmalloc' > \
  280. /sys/kernel/debug/tracing/events/syscalls/sys_exit_read/trigger
  281. The format is:
  282. enable_event:<system>:<event>[:count]
  283. disable_event:<system>:<event>[:count]
  284. To remove the above commands:
  285. # echo '!enable_event:kmem:kmalloc:1' > \
  286. /sys/kernel/debug/tracing/events/syscalls/sys_enter_read/trigger
  287. # echo '!disable_event:kmem:kmalloc' > \
  288. /sys/kernel/debug/tracing/events/syscalls/sys_exit_read/trigger
  289. Note that there can be any number of enable/disable_event triggers
  290. per triggering event, but there can only be one trigger per
  291. triggered event. e.g. sys_enter_read can have triggers enabling both
  292. kmem:kmalloc and sched:sched_switch, but can't have two kmem:kmalloc
  293. versions such as kmem:kmalloc and kmem:kmalloc:1 or 'kmem:kmalloc if
  294. bytes_req == 256' and 'kmem:kmalloc if bytes_alloc == 256' (they
  295. could be combined into a single filter on kmem:kmalloc though).
  296. - stacktrace
  297. This command dumps a stacktrace in the trace buffer whenever the
  298. triggering event occurs.
  299. For example, the following trigger dumps a stacktrace every time the
  300. kmalloc tracepoint is hit:
  301. # echo 'stacktrace' > \
  302. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  303. The following trigger dumps a stacktrace the first 5 times a kmalloc
  304. request happens with a size >= 64K
  305. # echo 'stacktrace:5 if bytes_req >= 65536' > \
  306. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  307. The format is:
  308. stacktrace[:count]
  309. To remove the above commands:
  310. # echo '!stacktrace' > \
  311. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  312. # echo '!stacktrace:5 if bytes_req >= 65536' > \
  313. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  314. The latter can also be removed more simply by the following (without
  315. the filter):
  316. # echo '!stacktrace:5' > \
  317. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  318. Note that there can be only one stacktrace trigger per triggering
  319. event.
  320. - snapshot
  321. This command causes a snapshot to be triggered whenever the
  322. triggering event occurs.
  323. The following command creates a snapshot every time a block request
  324. queue is unplugged with a depth > 1. If you were tracing a set of
  325. events or functions at the time, the snapshot trace buffer would
  326. capture those events when the trigger event occurred:
  327. # echo 'snapshot if nr_rq > 1' > \
  328. /sys/kernel/debug/tracing/events/block/block_unplug/trigger
  329. To only snapshot once:
  330. # echo 'snapshot:1 if nr_rq > 1' > \
  331. /sys/kernel/debug/tracing/events/block/block_unplug/trigger
  332. To remove the above commands:
  333. # echo '!snapshot if nr_rq > 1' > \
  334. /sys/kernel/debug/tracing/events/block/block_unplug/trigger
  335. # echo '!snapshot:1 if nr_rq > 1' > \
  336. /sys/kernel/debug/tracing/events/block/block_unplug/trigger
  337. Note that there can be only one snapshot trigger per triggering
  338. event.
  339. - traceon/traceoff
  340. These commands turn tracing on and off when the specified events are
  341. hit. The parameter determines how many times the tracing system is
  342. turned on and off. If unspecified, there is no limit.
  343. The following command turns tracing off the first time a block
  344. request queue is unplugged with a depth > 1. If you were tracing a
  345. set of events or functions at the time, you could then examine the
  346. trace buffer to see the sequence of events that led up to the
  347. trigger event:
  348. # echo 'traceoff:1 if nr_rq > 1' > \
  349. /sys/kernel/debug/tracing/events/block/block_unplug/trigger
  350. To always disable tracing when nr_rq > 1 :
  351. # echo 'traceoff if nr_rq > 1' > \
  352. /sys/kernel/debug/tracing/events/block/block_unplug/trigger
  353. To remove the above commands:
  354. # echo '!traceoff:1 if nr_rq > 1' > \
  355. /sys/kernel/debug/tracing/events/block/block_unplug/trigger
  356. # echo '!traceoff if nr_rq > 1' > \
  357. /sys/kernel/debug/tracing/events/block/block_unplug/trigger
  358. Note that there can be only one traceon or traceoff trigger per
  359. triggering event.
  360. - hist
  361. This command aggregates event hits into a hash table keyed on one or
  362. more trace event format fields (or stacktrace) and a set of running
  363. totals derived from one or more trace event format fields and/or
  364. event counts (hitcount).
  365. The format of a hist trigger is as follows:
  366. hist:keys=<field1[,field2,...]>[:values=<field1[,field2,...]>]
  367. [:sort=<field1[,field2,...]>][:size=#entries][:pause][:continue]
  368. [:clear][:name=histname1] [if <filter>]
  369. When a matching event is hit, an entry is added to a hash table
  370. using the key(s) and value(s) named. Keys and values correspond to
  371. fields in the event's format description. Values must correspond to
  372. numeric fields - on an event hit, the value(s) will be added to a
  373. sum kept for that field. The special string 'hitcount' can be used
  374. in place of an explicit value field - this is simply a count of
  375. event hits. If 'values' isn't specified, an implicit 'hitcount'
  376. value will be automatically created and used as the only value.
  377. Keys can be any field, or the special string 'stacktrace', which
  378. will use the event's kernel stacktrace as the key. The keywords
  379. 'keys' or 'key' can be used to specify keys, and the keywords
  380. 'values', 'vals', or 'val' can be used to specify values. Compound
  381. keys consisting of up to two fields can be specified by the 'keys'
  382. keyword. Hashing a compound key produces a unique entry in the
  383. table for each unique combination of component keys, and can be
  384. useful for providing more fine-grained summaries of event data.
  385. Additionally, sort keys consisting of up to two fields can be
  386. specified by the 'sort' keyword. If more than one field is
  387. specified, the result will be a 'sort within a sort': the first key
  388. is taken to be the primary sort key and the second the secondary
  389. key. If a hist trigger is given a name using the 'name' parameter,
  390. its histogram data will be shared with other triggers of the same
  391. name, and trigger hits will update this common data. Only triggers
  392. with 'compatible' fields can be combined in this way; triggers are
  393. 'compatible' if the fields named in the trigger share the same
  394. number and type of fields and those fields also have the same names.
  395. Note that any two events always share the compatible 'hitcount' and
  396. 'stacktrace' fields and can therefore be combined using those
  397. fields, however pointless that may be.
  398. 'hist' triggers add a 'hist' file to each event's subdirectory.
  399. Reading the 'hist' file for the event will dump the hash table in
  400. its entirety to stdout. If there are multiple hist triggers
  401. attached to an event, there will be a table for each trigger in the
  402. output. The table displayed for a named trigger will be the same as
  403. any other instance having the same name. Each printed hash table
  404. entry is a simple list of the keys and values comprising the entry;
  405. keys are printed first and are delineated by curly braces, and are
  406. followed by the set of value fields for the entry. By default,
  407. numeric fields are displayed as base-10 integers. This can be
  408. modified by appending any of the following modifiers to the field
  409. name:
  410. .hex display a number as a hex value
  411. .sym display an address as a symbol
  412. .sym-offset display an address as a symbol and offset
  413. .syscall display a syscall id as a system call name
  414. .execname display a common_pid as a program name
  415. Note that in general the semantics of a given field aren't
  416. interpreted when applying a modifier to it, but there are some
  417. restrictions to be aware of in this regard:
  418. - only the 'hex' modifier can be used for values (because values
  419. are essentially sums, and the other modifiers don't make sense
  420. in that context).
  421. - the 'execname' modifier can only be used on a 'common_pid'. The
  422. reason for this is that the execname is simply the 'comm' value
  423. saved for the 'current' process when an event was triggered,
  424. which is the same as the common_pid value saved by the event
  425. tracing code. Trying to apply that comm value to other pid
  426. values wouldn't be correct, and typically events that care save
  427. pid-specific comm fields in the event itself.
  428. A typical usage scenario would be the following to enable a hist
  429. trigger, read its current contents, and then turn it off:
  430. # echo 'hist:keys=skbaddr.hex:vals=len' > \
  431. /sys/kernel/debug/tracing/events/net/netif_rx/trigger
  432. # cat /sys/kernel/debug/tracing/events/net/netif_rx/hist
  433. # echo '!hist:keys=skbaddr.hex:vals=len' > \
  434. /sys/kernel/debug/tracing/events/net/netif_rx/trigger
  435. The trigger file itself can be read to show the details of the
  436. currently attached hist trigger. This information is also displayed
  437. at the top of the 'hist' file when read.
  438. By default, the size of the hash table is 2048 entries. The 'size'
  439. parameter can be used to specify more or fewer than that. The units
  440. are in terms of hashtable entries - if a run uses more entries than
  441. specified, the results will show the number of 'drops', the number
  442. of hits that were ignored. The size should be a power of 2 between
  443. 128 and 131072 (any non- power-of-2 number specified will be rounded
  444. up).
  445. The 'sort' parameter can be used to specify a value field to sort
  446. on. The default if unspecified is 'hitcount' and the default sort
  447. order is 'ascending'. To sort in the opposite direction, append
  448. .descending' to the sort key.
  449. The 'pause' parameter can be used to pause an existing hist trigger
  450. or to start a hist trigger but not log any events until told to do
  451. so. 'continue' or 'cont' can be used to start or restart a paused
  452. hist trigger.
  453. The 'clear' parameter will clear the contents of a running hist
  454. trigger and leave its current paused/active state.
  455. Note that the 'pause', 'cont', and 'clear' parameters should be
  456. applied using 'append' shell operator ('>>') if applied to an
  457. existing trigger, rather than via the '>' operator, which will cause
  458. the trigger to be removed through truncation.
  459. - enable_hist/disable_hist
  460. The enable_hist and disable_hist triggers can be used to have one
  461. event conditionally start and stop another event's already-attached
  462. hist trigger. Any number of enable_hist and disable_hist triggers
  463. can be attached to a given event, allowing that event to kick off
  464. and stop aggregations on a host of other events.
  465. The format is very similar to the enable/disable_event triggers:
  466. enable_hist:<system>:<event>[:count]
  467. disable_hist:<system>:<event>[:count]
  468. Instead of enabling or disabling the tracing of the target event
  469. into the trace buffer as the enable/disable_event triggers do, the
  470. enable/disable_hist triggers enable or disable the aggregation of
  471. the target event into a hash table.
  472. A typical usage scenario for the enable_hist/disable_hist triggers
  473. would be to first set up a paused hist trigger on some event,
  474. followed by an enable_hist/disable_hist pair that turns the hist
  475. aggregation on and off when conditions of interest are hit:
  476. # echo 'hist:keys=skbaddr.hex:vals=len:pause' > \
  477. /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
  478. # echo 'enable_hist:net:netif_receive_skb if filename==/usr/bin/wget' > \
  479. /sys/kernel/debug/tracing/events/sched/sched_process_exec/trigger
  480. # echo 'disable_hist:net:netif_receive_skb if comm==wget' > \
  481. /sys/kernel/debug/tracing/events/sched/sched_process_exit/trigger
  482. The above sets up an initially paused hist trigger which is unpaused
  483. and starts aggregating events when a given program is executed, and
  484. which stops aggregating when the process exits and the hist trigger
  485. is paused again.
  486. The examples below provide a more concrete illustration of the
  487. concepts and typical usage patterns discussed above.
  488. 6.2 'hist' trigger examples
  489. ---------------------------
  490. The first set of examples creates aggregations using the kmalloc
  491. event. The fields that can be used for the hist trigger are listed
  492. in the kmalloc event's format file:
  493. # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/format
  494. name: kmalloc
  495. ID: 374
  496. format:
  497. field:unsigned short common_type; offset:0; size:2; signed:0;
  498. field:unsigned char common_flags; offset:2; size:1; signed:0;
  499. field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
  500. field:int common_pid; offset:4; size:4; signed:1;
  501. field:unsigned long call_site; offset:8; size:8; signed:0;
  502. field:const void * ptr; offset:16; size:8; signed:0;
  503. field:size_t bytes_req; offset:24; size:8; signed:0;
  504. field:size_t bytes_alloc; offset:32; size:8; signed:0;
  505. field:gfp_t gfp_flags; offset:40; size:4; signed:0;
  506. We'll start by creating a hist trigger that generates a simple table
  507. that lists the total number of bytes requested for each function in
  508. the kernel that made one or more calls to kmalloc:
  509. # echo 'hist:key=call_site:val=bytes_req' > \
  510. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  511. This tells the tracing system to create a 'hist' trigger using the
  512. call_site field of the kmalloc event as the key for the table, which
  513. just means that each unique call_site address will have an entry
  514. created for it in the table. The 'val=bytes_req' parameter tells
  515. the hist trigger that for each unique entry (call_site) in the
  516. table, it should keep a running total of the number of bytes
  517. requested by that call_site.
  518. We'll let it run for awhile and then dump the contents of the 'hist'
  519. file in the kmalloc event's subdirectory (for readability, a number
  520. of entries have been omitted):
  521. # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
  522. # trigger info: hist:keys=call_site:vals=bytes_req:sort=hitcount:size=2048 [active]
  523. { call_site: 18446744072106379007 } hitcount: 1 bytes_req: 176
  524. { call_site: 18446744071579557049 } hitcount: 1 bytes_req: 1024
  525. { call_site: 18446744071580608289 } hitcount: 1 bytes_req: 16384
  526. { call_site: 18446744071581827654 } hitcount: 1 bytes_req: 24
  527. { call_site: 18446744071580700980 } hitcount: 1 bytes_req: 8
  528. { call_site: 18446744071579359876 } hitcount: 1 bytes_req: 152
  529. { call_site: 18446744071580795365 } hitcount: 3 bytes_req: 144
  530. { call_site: 18446744071581303129 } hitcount: 3 bytes_req: 144
  531. { call_site: 18446744071580713234 } hitcount: 4 bytes_req: 2560
  532. { call_site: 18446744071580933750 } hitcount: 4 bytes_req: 736
  533. .
  534. .
  535. .
  536. { call_site: 18446744072106047046 } hitcount: 69 bytes_req: 5576
  537. { call_site: 18446744071582116407 } hitcount: 73 bytes_req: 2336
  538. { call_site: 18446744072106054684 } hitcount: 136 bytes_req: 140504
  539. { call_site: 18446744072106224230 } hitcount: 136 bytes_req: 19584
  540. { call_site: 18446744072106078074 } hitcount: 153 bytes_req: 2448
  541. { call_site: 18446744072106062406 } hitcount: 153 bytes_req: 36720
  542. { call_site: 18446744071582507929 } hitcount: 153 bytes_req: 37088
  543. { call_site: 18446744072102520590 } hitcount: 273 bytes_req: 10920
  544. { call_site: 18446744071582143559 } hitcount: 358 bytes_req: 716
  545. { call_site: 18446744072106465852 } hitcount: 417 bytes_req: 56712
  546. { call_site: 18446744072102523378 } hitcount: 485 bytes_req: 27160
  547. { call_site: 18446744072099568646 } hitcount: 1676 bytes_req: 33520
  548. Totals:
  549. Hits: 4610
  550. Entries: 45
  551. Dropped: 0
  552. The output displays a line for each entry, beginning with the key
  553. specified in the trigger, followed by the value(s) also specified in
  554. the trigger. At the beginning of the output is a line that displays
  555. the trigger info, which can also be displayed by reading the
  556. 'trigger' file:
  557. # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  558. hist:keys=call_site:vals=bytes_req:sort=hitcount:size=2048 [active]
  559. At the end of the output are a few lines that display the overall
  560. totals for the run. The 'Hits' field shows the total number of
  561. times the event trigger was hit, the 'Entries' field shows the total
  562. number of used entries in the hash table, and the 'Dropped' field
  563. shows the number of hits that were dropped because the number of
  564. used entries for the run exceeded the maximum number of entries
  565. allowed for the table (normally 0, but if not a hint that you may
  566. want to increase the size of the table using the 'size' parameter).
  567. Notice in the above output that there's an extra field, 'hitcount',
  568. which wasn't specified in the trigger. Also notice that in the
  569. trigger info output, there's a parameter, 'sort=hitcount', which
  570. wasn't specified in the trigger either. The reason for that is that
  571. every trigger implicitly keeps a count of the total number of hits
  572. attributed to a given entry, called the 'hitcount'. That hitcount
  573. information is explicitly displayed in the output, and in the
  574. absence of a user-specified sort parameter, is used as the default
  575. sort field.
  576. The value 'hitcount' can be used in place of an explicit value in
  577. the 'values' parameter if you don't really need to have any
  578. particular field summed and are mainly interested in hit
  579. frequencies.
  580. To turn the hist trigger off, simply call up the trigger in the
  581. command history and re-execute it with a '!' prepended:
  582. # echo '!hist:key=call_site:val=bytes_req' > \
  583. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  584. Finally, notice that the call_site as displayed in the output above
  585. isn't really very useful. It's an address, but normally addresses
  586. are displayed in hex. To have a numeric field displayed as a hex
  587. value, simply append '.hex' to the field name in the trigger:
  588. # echo 'hist:key=call_site.hex:val=bytes_req' > \
  589. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  590. # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
  591. # trigger info: hist:keys=call_site.hex:vals=bytes_req:sort=hitcount:size=2048 [active]
  592. { call_site: ffffffffa026b291 } hitcount: 1 bytes_req: 433
  593. { call_site: ffffffffa07186ff } hitcount: 1 bytes_req: 176
  594. { call_site: ffffffff811ae721 } hitcount: 1 bytes_req: 16384
  595. { call_site: ffffffff811c5134 } hitcount: 1 bytes_req: 8
  596. { call_site: ffffffffa04a9ebb } hitcount: 1 bytes_req: 511
  597. { call_site: ffffffff8122e0a6 } hitcount: 1 bytes_req: 12
  598. { call_site: ffffffff8107da84 } hitcount: 1 bytes_req: 152
  599. { call_site: ffffffff812d8246 } hitcount: 1 bytes_req: 24
  600. { call_site: ffffffff811dc1e5 } hitcount: 3 bytes_req: 144
  601. { call_site: ffffffffa02515e8 } hitcount: 3 bytes_req: 648
  602. { call_site: ffffffff81258159 } hitcount: 3 bytes_req: 144
  603. { call_site: ffffffff811c80f4 } hitcount: 4 bytes_req: 544
  604. .
  605. .
  606. .
  607. { call_site: ffffffffa06c7646 } hitcount: 106 bytes_req: 8024
  608. { call_site: ffffffffa06cb246 } hitcount: 132 bytes_req: 31680
  609. { call_site: ffffffffa06cef7a } hitcount: 132 bytes_req: 2112
  610. { call_site: ffffffff8137e399 } hitcount: 132 bytes_req: 23232
  611. { call_site: ffffffffa06c941c } hitcount: 185 bytes_req: 171360
  612. { call_site: ffffffffa06f2a66 } hitcount: 185 bytes_req: 26640
  613. { call_site: ffffffffa036a70e } hitcount: 265 bytes_req: 10600
  614. { call_site: ffffffff81325447 } hitcount: 292 bytes_req: 584
  615. { call_site: ffffffffa072da3c } hitcount: 446 bytes_req: 60656
  616. { call_site: ffffffffa036b1f2 } hitcount: 526 bytes_req: 29456
  617. { call_site: ffffffffa0099c06 } hitcount: 1780 bytes_req: 35600
  618. Totals:
  619. Hits: 4775
  620. Entries: 46
  621. Dropped: 0
  622. Even that's only marginally more useful - while hex values do look
  623. more like addresses, what users are typically more interested in
  624. when looking at text addresses are the corresponding symbols
  625. instead. To have an address displayed as symbolic value instead,
  626. simply append '.sym' or '.sym-offset' to the field name in the
  627. trigger:
  628. # echo 'hist:key=call_site.sym:val=bytes_req' > \
  629. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  630. # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
  631. # trigger info: hist:keys=call_site.sym:vals=bytes_req:sort=hitcount:size=2048 [active]
  632. { call_site: [ffffffff810adcb9] syslog_print_all } hitcount: 1 bytes_req: 1024
  633. { call_site: [ffffffff8154bc62] usb_control_msg } hitcount: 1 bytes_req: 8
  634. { call_site: [ffffffffa00bf6fe] hidraw_send_report [hid] } hitcount: 1 bytes_req: 7
  635. { call_site: [ffffffff8154acbe] usb_alloc_urb } hitcount: 1 bytes_req: 192
  636. { call_site: [ffffffffa00bf1ca] hidraw_report_event [hid] } hitcount: 1 bytes_req: 7
  637. { call_site: [ffffffff811e3a25] __seq_open_private } hitcount: 1 bytes_req: 40
  638. { call_site: [ffffffff8109524a] alloc_fair_sched_group } hitcount: 2 bytes_req: 128
  639. { call_site: [ffffffff811febd5] fsnotify_alloc_group } hitcount: 2 bytes_req: 528
  640. { call_site: [ffffffff81440f58] __tty_buffer_request_room } hitcount: 2 bytes_req: 2624
  641. { call_site: [ffffffff81200ba6] inotify_new_group } hitcount: 2 bytes_req: 96
  642. { call_site: [ffffffffa05e19af] ieee80211_start_tx_ba_session [mac80211] } hitcount: 2 bytes_req: 464
  643. { call_site: [ffffffff81672406] tcp_get_metrics } hitcount: 2 bytes_req: 304
  644. { call_site: [ffffffff81097ec2] alloc_rt_sched_group } hitcount: 2 bytes_req: 128
  645. { call_site: [ffffffff81089b05] sched_create_group } hitcount: 2 bytes_req: 1424
  646. .
  647. .
  648. .
  649. { call_site: [ffffffffa04a580c] intel_crtc_page_flip [i915] } hitcount: 1185 bytes_req: 123240
  650. { call_site: [ffffffffa0287592] drm_mode_page_flip_ioctl [drm] } hitcount: 1185 bytes_req: 104280
  651. { call_site: [ffffffffa04c4a3c] intel_plane_duplicate_state [i915] } hitcount: 1402 bytes_req: 190672
  652. { call_site: [ffffffff812891ca] ext4_find_extent } hitcount: 1518 bytes_req: 146208
  653. { call_site: [ffffffffa029070e] drm_vma_node_allow [drm] } hitcount: 1746 bytes_req: 69840
  654. { call_site: [ffffffffa045e7c4] i915_gem_do_execbuffer.isra.23 [i915] } hitcount: 2021 bytes_req: 792312
  655. { call_site: [ffffffffa02911f2] drm_modeset_lock_crtc [drm] } hitcount: 2592 bytes_req: 145152
  656. { call_site: [ffffffffa0489a66] intel_ring_begin [i915] } hitcount: 2629 bytes_req: 378576
  657. { call_site: [ffffffffa046041c] i915_gem_execbuffer2 [i915] } hitcount: 2629 bytes_req: 3783248
  658. { call_site: [ffffffff81325607] apparmor_file_alloc_security } hitcount: 5192 bytes_req: 10384
  659. { call_site: [ffffffffa00b7c06] hid_report_raw_event [hid] } hitcount: 5529 bytes_req: 110584
  660. { call_site: [ffffffff8131ebf7] aa_alloc_task_context } hitcount: 21943 bytes_req: 702176
  661. { call_site: [ffffffff8125847d] ext4_htree_store_dirent } hitcount: 55759 bytes_req: 5074265
  662. Totals:
  663. Hits: 109928
  664. Entries: 71
  665. Dropped: 0
  666. Because the default sort key above is 'hitcount', the above shows a
  667. the list of call_sites by increasing hitcount, so that at the bottom
  668. we see the functions that made the most kmalloc calls during the
  669. run. If instead we we wanted to see the top kmalloc callers in
  670. terms of the number of bytes requested rather than the number of
  671. calls, and we wanted the top caller to appear at the top, we can use
  672. the 'sort' parameter, along with the 'descending' modifier:
  673. # echo 'hist:key=call_site.sym:val=bytes_req:sort=bytes_req.descending' > \
  674. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  675. # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
  676. # trigger info: hist:keys=call_site.sym:vals=bytes_req:sort=bytes_req.descending:size=2048 [active]
  677. { call_site: [ffffffffa046041c] i915_gem_execbuffer2 [i915] } hitcount: 2186 bytes_req: 3397464
  678. { call_site: [ffffffffa045e7c4] i915_gem_do_execbuffer.isra.23 [i915] } hitcount: 1790 bytes_req: 712176
  679. { call_site: [ffffffff8125847d] ext4_htree_store_dirent } hitcount: 8132 bytes_req: 513135
  680. { call_site: [ffffffff811e2a1b] seq_buf_alloc } hitcount: 106 bytes_req: 440128
  681. { call_site: [ffffffffa0489a66] intel_ring_begin [i915] } hitcount: 2186 bytes_req: 314784
  682. { call_site: [ffffffff812891ca] ext4_find_extent } hitcount: 2174 bytes_req: 208992
  683. { call_site: [ffffffff811ae8e1] __kmalloc } hitcount: 8 bytes_req: 131072
  684. { call_site: [ffffffffa04c4a3c] intel_plane_duplicate_state [i915] } hitcount: 859 bytes_req: 116824
  685. { call_site: [ffffffffa02911f2] drm_modeset_lock_crtc [drm] } hitcount: 1834 bytes_req: 102704
  686. { call_site: [ffffffffa04a580c] intel_crtc_page_flip [i915] } hitcount: 972 bytes_req: 101088
  687. { call_site: [ffffffffa0287592] drm_mode_page_flip_ioctl [drm] } hitcount: 972 bytes_req: 85536
  688. { call_site: [ffffffffa00b7c06] hid_report_raw_event [hid] } hitcount: 3333 bytes_req: 66664
  689. { call_site: [ffffffff8137e559] sg_kmalloc } hitcount: 209 bytes_req: 61632
  690. .
  691. .
  692. .
  693. { call_site: [ffffffff81095225] alloc_fair_sched_group } hitcount: 2 bytes_req: 128
  694. { call_site: [ffffffff81097ec2] alloc_rt_sched_group } hitcount: 2 bytes_req: 128
  695. { call_site: [ffffffff812d8406] copy_semundo } hitcount: 2 bytes_req: 48
  696. { call_site: [ffffffff81200ba6] inotify_new_group } hitcount: 1 bytes_req: 48
  697. { call_site: [ffffffffa027121a] drm_getmagic [drm] } hitcount: 1 bytes_req: 48
  698. { call_site: [ffffffff811e3a25] __seq_open_private } hitcount: 1 bytes_req: 40
  699. { call_site: [ffffffff811c52f4] bprm_change_interp } hitcount: 2 bytes_req: 16
  700. { call_site: [ffffffff8154bc62] usb_control_msg } hitcount: 1 bytes_req: 8
  701. { call_site: [ffffffffa00bf1ca] hidraw_report_event [hid] } hitcount: 1 bytes_req: 7
  702. { call_site: [ffffffffa00bf6fe] hidraw_send_report [hid] } hitcount: 1 bytes_req: 7
  703. Totals:
  704. Hits: 32133
  705. Entries: 81
  706. Dropped: 0
  707. To display the offset and size information in addition to the symbol
  708. name, just use 'sym-offset' instead:
  709. # echo 'hist:key=call_site.sym-offset:val=bytes_req:sort=bytes_req.descending' > \
  710. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  711. # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
  712. # trigger info: hist:keys=call_site.sym-offset:vals=bytes_req:sort=bytes_req.descending:size=2048 [active]
  713. { call_site: [ffffffffa046041c] i915_gem_execbuffer2+0x6c/0x2c0 [i915] } hitcount: 4569 bytes_req: 3163720
  714. { call_site: [ffffffffa0489a66] intel_ring_begin+0xc6/0x1f0 [i915] } hitcount: 4569 bytes_req: 657936
  715. { call_site: [ffffffffa045e7c4] i915_gem_do_execbuffer.isra.23+0x694/0x1020 [i915] } hitcount: 1519 bytes_req: 472936
  716. { call_site: [ffffffffa045e646] i915_gem_do_execbuffer.isra.23+0x516/0x1020 [i915] } hitcount: 3050 bytes_req: 211832
  717. { call_site: [ffffffff811e2a1b] seq_buf_alloc+0x1b/0x50 } hitcount: 34 bytes_req: 148384
  718. { call_site: [ffffffffa04a580c] intel_crtc_page_flip+0xbc/0x870 [i915] } hitcount: 1385 bytes_req: 144040
  719. { call_site: [ffffffff811ae8e1] __kmalloc+0x191/0x1b0 } hitcount: 8 bytes_req: 131072
  720. { call_site: [ffffffffa0287592] drm_mode_page_flip_ioctl+0x282/0x360 [drm] } hitcount: 1385 bytes_req: 121880
  721. { call_site: [ffffffffa02911f2] drm_modeset_lock_crtc+0x32/0x100 [drm] } hitcount: 1848 bytes_req: 103488
  722. { call_site: [ffffffffa04c4a3c] intel_plane_duplicate_state+0x2c/0xa0 [i915] } hitcount: 461 bytes_req: 62696
  723. { call_site: [ffffffffa029070e] drm_vma_node_allow+0x2e/0xd0 [drm] } hitcount: 1541 bytes_req: 61640
  724. { call_site: [ffffffff815f8d7b] sk_prot_alloc+0xcb/0x1b0 } hitcount: 57 bytes_req: 57456
  725. .
  726. .
  727. .
  728. { call_site: [ffffffff8109524a] alloc_fair_sched_group+0x5a/0x1a0 } hitcount: 2 bytes_req: 128
  729. { call_site: [ffffffffa027b921] drm_vm_open_locked+0x31/0xa0 [drm] } hitcount: 3 bytes_req: 96
  730. { call_site: [ffffffff8122e266] proc_self_follow_link+0x76/0xb0 } hitcount: 8 bytes_req: 96
  731. { call_site: [ffffffff81213e80] load_elf_binary+0x240/0x1650 } hitcount: 3 bytes_req: 84
  732. { call_site: [ffffffff8154bc62] usb_control_msg+0x42/0x110 } hitcount: 1 bytes_req: 8
  733. { call_site: [ffffffffa00bf6fe] hidraw_send_report+0x7e/0x1a0 [hid] } hitcount: 1 bytes_req: 7
  734. { call_site: [ffffffffa00bf1ca] hidraw_report_event+0x8a/0x120 [hid] } hitcount: 1 bytes_req: 7
  735. Totals:
  736. Hits: 26098
  737. Entries: 64
  738. Dropped: 0
  739. We can also add multiple fields to the 'values' parameter. For
  740. example, we might want to see the total number of bytes allocated
  741. alongside bytes requested, and display the result sorted by bytes
  742. allocated in a descending order:
  743. # echo 'hist:keys=call_site.sym:values=bytes_req,bytes_alloc:sort=bytes_alloc.descending' > \
  744. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  745. # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
  746. # trigger info: hist:keys=call_site.sym:vals=bytes_req,bytes_alloc:sort=bytes_alloc.descending:size=2048 [active]
  747. { call_site: [ffffffffa046041c] i915_gem_execbuffer2 [i915] } hitcount: 7403 bytes_req: 4084360 bytes_alloc: 5958016
  748. { call_site: [ffffffff811e2a1b] seq_buf_alloc } hitcount: 541 bytes_req: 2213968 bytes_alloc: 2228224
  749. { call_site: [ffffffffa0489a66] intel_ring_begin [i915] } hitcount: 7404 bytes_req: 1066176 bytes_alloc: 1421568
  750. { call_site: [ffffffffa045e7c4] i915_gem_do_execbuffer.isra.23 [i915] } hitcount: 1565 bytes_req: 557368 bytes_alloc: 1037760
  751. { call_site: [ffffffff8125847d] ext4_htree_store_dirent } hitcount: 9557 bytes_req: 595778 bytes_alloc: 695744
  752. { call_site: [ffffffffa045e646] i915_gem_do_execbuffer.isra.23 [i915] } hitcount: 5839 bytes_req: 430680 bytes_alloc: 470400
  753. { call_site: [ffffffffa04c4a3c] intel_plane_duplicate_state [i915] } hitcount: 2388 bytes_req: 324768 bytes_alloc: 458496
  754. { call_site: [ffffffffa02911f2] drm_modeset_lock_crtc [drm] } hitcount: 3911 bytes_req: 219016 bytes_alloc: 250304
  755. { call_site: [ffffffff815f8d7b] sk_prot_alloc } hitcount: 235 bytes_req: 236880 bytes_alloc: 240640
  756. { call_site: [ffffffff8137e559] sg_kmalloc } hitcount: 557 bytes_req: 169024 bytes_alloc: 221760
  757. { call_site: [ffffffffa00b7c06] hid_report_raw_event [hid] } hitcount: 9378 bytes_req: 187548 bytes_alloc: 206312
  758. { call_site: [ffffffffa04a580c] intel_crtc_page_flip [i915] } hitcount: 1519 bytes_req: 157976 bytes_alloc: 194432
  759. .
  760. .
  761. .
  762. { call_site: [ffffffff8109bd3b] sched_autogroup_create_attach } hitcount: 2 bytes_req: 144 bytes_alloc: 192
  763. { call_site: [ffffffff81097ee8] alloc_rt_sched_group } hitcount: 2 bytes_req: 128 bytes_alloc: 128
  764. { call_site: [ffffffff8109524a] alloc_fair_sched_group } hitcount: 2 bytes_req: 128 bytes_alloc: 128
  765. { call_site: [ffffffff81095225] alloc_fair_sched_group } hitcount: 2 bytes_req: 128 bytes_alloc: 128
  766. { call_site: [ffffffff81097ec2] alloc_rt_sched_group } hitcount: 2 bytes_req: 128 bytes_alloc: 128
  767. { call_site: [ffffffff81213e80] load_elf_binary } hitcount: 3 bytes_req: 84 bytes_alloc: 96
  768. { call_site: [ffffffff81079a2e] kthread_create_on_node } hitcount: 1 bytes_req: 56 bytes_alloc: 64
  769. { call_site: [ffffffffa00bf6fe] hidraw_send_report [hid] } hitcount: 1 bytes_req: 7 bytes_alloc: 8
  770. { call_site: [ffffffff8154bc62] usb_control_msg } hitcount: 1 bytes_req: 8 bytes_alloc: 8
  771. { call_site: [ffffffffa00bf1ca] hidraw_report_event [hid] } hitcount: 1 bytes_req: 7 bytes_alloc: 8
  772. Totals:
  773. Hits: 66598
  774. Entries: 65
  775. Dropped: 0
  776. Finally, to finish off our kmalloc example, instead of simply having
  777. the hist trigger display symbolic call_sites, we can have the hist
  778. trigger additionally display the complete set of kernel stack traces
  779. that led to each call_site. To do that, we simply use the special
  780. value 'stacktrace' for the key parameter:
  781. # echo 'hist:keys=stacktrace:values=bytes_req,bytes_alloc:sort=bytes_alloc' > \
  782. /sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
  783. The above trigger will use the kernel stack trace in effect when an
  784. event is triggered as the key for the hash table. This allows the
  785. enumeration of every kernel callpath that led up to a particular
  786. event, along with a running total of any of the event fields for
  787. that event. Here we tally bytes requested and bytes allocated for
  788. every callpath in the system that led up to a kmalloc (in this case
  789. every callpath to a kmalloc for a kernel compile):
  790. # cat /sys/kernel/debug/tracing/events/kmem/kmalloc/hist
  791. # trigger info: hist:keys=stacktrace:vals=bytes_req,bytes_alloc:sort=bytes_alloc:size=2048 [active]
  792. { stacktrace:
  793. __kmalloc_track_caller+0x10b/0x1a0
  794. kmemdup+0x20/0x50
  795. hidraw_report_event+0x8a/0x120 [hid]
  796. hid_report_raw_event+0x3ea/0x440 [hid]
  797. hid_input_report+0x112/0x190 [hid]
  798. hid_irq_in+0xc2/0x260 [usbhid]
  799. __usb_hcd_giveback_urb+0x72/0x120
  800. usb_giveback_urb_bh+0x9e/0xe0
  801. tasklet_hi_action+0xf8/0x100
  802. __do_softirq+0x114/0x2c0
  803. irq_exit+0xa5/0xb0
  804. do_IRQ+0x5a/0xf0
  805. ret_from_intr+0x0/0x30
  806. cpuidle_enter+0x17/0x20
  807. cpu_startup_entry+0x315/0x3e0
  808. rest_init+0x7c/0x80
  809. } hitcount: 3 bytes_req: 21 bytes_alloc: 24
  810. { stacktrace:
  811. __kmalloc_track_caller+0x10b/0x1a0
  812. kmemdup+0x20/0x50
  813. hidraw_report_event+0x8a/0x120 [hid]
  814. hid_report_raw_event+0x3ea/0x440 [hid]
  815. hid_input_report+0x112/0x190 [hid]
  816. hid_irq_in+0xc2/0x260 [usbhid]
  817. __usb_hcd_giveback_urb+0x72/0x120
  818. usb_giveback_urb_bh+0x9e/0xe0
  819. tasklet_hi_action+0xf8/0x100
  820. __do_softirq+0x114/0x2c0
  821. irq_exit+0xa5/0xb0
  822. do_IRQ+0x5a/0xf0
  823. ret_from_intr+0x0/0x30
  824. } hitcount: 3 bytes_req: 21 bytes_alloc: 24
  825. { stacktrace:
  826. kmem_cache_alloc_trace+0xeb/0x150
  827. aa_alloc_task_context+0x27/0x40
  828. apparmor_cred_prepare+0x1f/0x50
  829. security_prepare_creds+0x16/0x20
  830. prepare_creds+0xdf/0x1a0
  831. SyS_capset+0xb5/0x200
  832. system_call_fastpath+0x12/0x6a
  833. } hitcount: 1 bytes_req: 32 bytes_alloc: 32
  834. .
  835. .
  836. .
  837. { stacktrace:
  838. __kmalloc+0x11b/0x1b0
  839. i915_gem_execbuffer2+0x6c/0x2c0 [i915]
  840. drm_ioctl+0x349/0x670 [drm]
  841. do_vfs_ioctl+0x2f0/0x4f0
  842. SyS_ioctl+0x81/0xa0
  843. system_call_fastpath+0x12/0x6a
  844. } hitcount: 17726 bytes_req: 13944120 bytes_alloc: 19593808
  845. { stacktrace:
  846. __kmalloc+0x11b/0x1b0
  847. load_elf_phdrs+0x76/0xa0
  848. load_elf_binary+0x102/0x1650
  849. search_binary_handler+0x97/0x1d0
  850. do_execveat_common.isra.34+0x551/0x6e0
  851. SyS_execve+0x3a/0x50
  852. return_from_execve+0x0/0x23
  853. } hitcount: 33348 bytes_req: 17152128 bytes_alloc: 20226048
  854. { stacktrace:
  855. kmem_cache_alloc_trace+0xeb/0x150
  856. apparmor_file_alloc_security+0x27/0x40
  857. security_file_alloc+0x16/0x20
  858. get_empty_filp+0x93/0x1c0
  859. path_openat+0x31/0x5f0
  860. do_filp_open+0x3a/0x90
  861. do_sys_open+0x128/0x220
  862. SyS_open+0x1e/0x20
  863. system_call_fastpath+0x12/0x6a
  864. } hitcount: 4766422 bytes_req: 9532844 bytes_alloc: 38131376
  865. { stacktrace:
  866. __kmalloc+0x11b/0x1b0
  867. seq_buf_alloc+0x1b/0x50
  868. seq_read+0x2cc/0x370
  869. proc_reg_read+0x3d/0x80
  870. __vfs_read+0x28/0xe0
  871. vfs_read+0x86/0x140
  872. SyS_read+0x46/0xb0
  873. system_call_fastpath+0x12/0x6a
  874. } hitcount: 19133 bytes_req: 78368768 bytes_alloc: 78368768
  875. Totals:
  876. Hits: 6085872
  877. Entries: 253
  878. Dropped: 0
  879. If you key a hist trigger on common_pid, in order for example to
  880. gather and display sorted totals for each process, you can use the
  881. special .execname modifier to display the executable names for the
  882. processes in the table rather than raw pids. The example below
  883. keeps a per-process sum of total bytes read:
  884. # echo 'hist:key=common_pid.execname:val=count:sort=count.descending' > \
  885. /sys/kernel/debug/tracing/events/syscalls/sys_enter_read/trigger
  886. # cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_read/hist
  887. # trigger info: hist:keys=common_pid.execname:vals=count:sort=count.descending:size=2048 [active]
  888. { common_pid: gnome-terminal [ 3196] } hitcount: 280 count: 1093512
  889. { common_pid: Xorg [ 1309] } hitcount: 525 count: 256640
  890. { common_pid: compiz [ 2889] } hitcount: 59 count: 254400
  891. { common_pid: bash [ 8710] } hitcount: 3 count: 66369
  892. { common_pid: dbus-daemon-lau [ 8703] } hitcount: 49 count: 47739
  893. { common_pid: irqbalance [ 1252] } hitcount: 27 count: 27648
  894. { common_pid: 01ifupdown [ 8705] } hitcount: 3 count: 17216
  895. { common_pid: dbus-daemon [ 772] } hitcount: 10 count: 12396
  896. { common_pid: Socket Thread [ 8342] } hitcount: 11 count: 11264
  897. { common_pid: nm-dhcp-client. [ 8701] } hitcount: 6 count: 7424
  898. { common_pid: gmain [ 1315] } hitcount: 18 count: 6336
  899. .
  900. .
  901. .
  902. { common_pid: postgres [ 1892] } hitcount: 2 count: 32
  903. { common_pid: postgres [ 1891] } hitcount: 2 count: 32
  904. { common_pid: gmain [ 8704] } hitcount: 2 count: 32
  905. { common_pid: upstart-dbus-br [ 2740] } hitcount: 21 count: 21
  906. { common_pid: nm-dispatcher.a [ 8696] } hitcount: 1 count: 16
  907. { common_pid: indicator-datet [ 2904] } hitcount: 1 count: 16
  908. { common_pid: gdbus [ 2998] } hitcount: 1 count: 16
  909. { common_pid: rtkit-daemon [ 2052] } hitcount: 1 count: 8
  910. { common_pid: init [ 1] } hitcount: 2 count: 2
  911. Totals:
  912. Hits: 2116
  913. Entries: 51
  914. Dropped: 0
  915. Similarly, if you key a hist trigger on syscall id, for example to
  916. gather and display a list of systemwide syscall hits, you can use
  917. the special .syscall modifier to display the syscall names rather
  918. than raw ids. The example below keeps a running total of syscall
  919. counts for the system during the run:
  920. # echo 'hist:key=id.syscall:val=hitcount' > \
  921. /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/trigger
  922. # cat /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/hist
  923. # trigger info: hist:keys=id.syscall:vals=hitcount:sort=hitcount:size=2048 [active]
  924. { id: sys_fsync [ 74] } hitcount: 1
  925. { id: sys_newuname [ 63] } hitcount: 1
  926. { id: sys_prctl [157] } hitcount: 1
  927. { id: sys_statfs [137] } hitcount: 1
  928. { id: sys_symlink [ 88] } hitcount: 1
  929. { id: sys_sendmmsg [307] } hitcount: 1
  930. { id: sys_semctl [ 66] } hitcount: 1
  931. { id: sys_readlink [ 89] } hitcount: 3
  932. { id: sys_bind [ 49] } hitcount: 3
  933. { id: sys_getsockname [ 51] } hitcount: 3
  934. { id: sys_unlink [ 87] } hitcount: 3
  935. { id: sys_rename [ 82] } hitcount: 4
  936. { id: unknown_syscall [ 58] } hitcount: 4
  937. { id: sys_connect [ 42] } hitcount: 4
  938. { id: sys_getpid [ 39] } hitcount: 4
  939. .
  940. .
  941. .
  942. { id: sys_rt_sigprocmask [ 14] } hitcount: 952
  943. { id: sys_futex [202] } hitcount: 1534
  944. { id: sys_write [ 1] } hitcount: 2689
  945. { id: sys_setitimer [ 38] } hitcount: 2797
  946. { id: sys_read [ 0] } hitcount: 3202
  947. { id: sys_select [ 23] } hitcount: 3773
  948. { id: sys_writev [ 20] } hitcount: 4531
  949. { id: sys_poll [ 7] } hitcount: 8314
  950. { id: sys_recvmsg [ 47] } hitcount: 13738
  951. { id: sys_ioctl [ 16] } hitcount: 21843
  952. Totals:
  953. Hits: 67612
  954. Entries: 72
  955. Dropped: 0
  956. The syscall counts above provide a rough overall picture of system
  957. call activity on the system; we can see for example that the most
  958. popular system call on this system was the 'sys_ioctl' system call.
  959. We can use 'compound' keys to refine that number and provide some
  960. further insight as to which processes exactly contribute to the
  961. overall ioctl count.
  962. The command below keeps a hitcount for every unique combination of
  963. system call id and pid - the end result is essentially a table
  964. that keeps a per-pid sum of system call hits. The results are
  965. sorted using the system call id as the primary key, and the
  966. hitcount sum as the secondary key:
  967. # echo 'hist:key=id.syscall,common_pid.execname:val=hitcount:sort=id,hitcount' > \
  968. /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/trigger
  969. # cat /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/hist
  970. # trigger info: hist:keys=id.syscall,common_pid.execname:vals=hitcount:sort=id.syscall,hitcount:size=2048 [active]
  971. { id: sys_read [ 0], common_pid: rtkit-daemon [ 1877] } hitcount: 1
  972. { id: sys_read [ 0], common_pid: gdbus [ 2976] } hitcount: 1
  973. { id: sys_read [ 0], common_pid: console-kit-dae [ 3400] } hitcount: 1
  974. { id: sys_read [ 0], common_pid: postgres [ 1865] } hitcount: 1
  975. { id: sys_read [ 0], common_pid: deja-dup-monito [ 3543] } hitcount: 2
  976. { id: sys_read [ 0], common_pid: NetworkManager [ 890] } hitcount: 2
  977. { id: sys_read [ 0], common_pid: evolution-calen [ 3048] } hitcount: 2
  978. { id: sys_read [ 0], common_pid: postgres [ 1864] } hitcount: 2
  979. { id: sys_read [ 0], common_pid: nm-applet [ 3022] } hitcount: 2
  980. { id: sys_read [ 0], common_pid: whoopsie [ 1212] } hitcount: 2
  981. .
  982. .
  983. .
  984. { id: sys_ioctl [ 16], common_pid: bash [ 8479] } hitcount: 1
  985. { id: sys_ioctl [ 16], common_pid: bash [ 3472] } hitcount: 12
  986. { id: sys_ioctl [ 16], common_pid: gnome-terminal [ 3199] } hitcount: 16
  987. { id: sys_ioctl [ 16], common_pid: Xorg [ 1267] } hitcount: 1808
  988. { id: sys_ioctl [ 16], common_pid: compiz [ 2994] } hitcount: 5580
  989. .
  990. .
  991. .
  992. { id: sys_waitid [247], common_pid: upstart-dbus-br [ 2690] } hitcount: 3
  993. { id: sys_waitid [247], common_pid: upstart-dbus-br [ 2688] } hitcount: 16
  994. { id: sys_inotify_add_watch [254], common_pid: gmain [ 975] } hitcount: 2
  995. { id: sys_inotify_add_watch [254], common_pid: gmain [ 3204] } hitcount: 4
  996. { id: sys_inotify_add_watch [254], common_pid: gmain [ 2888] } hitcount: 4
  997. { id: sys_inotify_add_watch [254], common_pid: gmain [ 3003] } hitcount: 4
  998. { id: sys_inotify_add_watch [254], common_pid: gmain [ 2873] } hitcount: 4
  999. { id: sys_inotify_add_watch [254], common_pid: gmain [ 3196] } hitcount: 6
  1000. { id: sys_openat [257], common_pid: java [ 2623] } hitcount: 2
  1001. { id: sys_eventfd2 [290], common_pid: ibus-ui-gtk3 [ 2760] } hitcount: 4
  1002. { id: sys_eventfd2 [290], common_pid: compiz [ 2994] } hitcount: 6
  1003. Totals:
  1004. Hits: 31536
  1005. Entries: 323
  1006. Dropped: 0
  1007. The above list does give us a breakdown of the ioctl syscall by
  1008. pid, but it also gives us quite a bit more than that, which we
  1009. don't really care about at the moment. Since we know the syscall
  1010. id for sys_ioctl (16, displayed next to the sys_ioctl name), we
  1011. can use that to filter out all the other syscalls:
  1012. # echo 'hist:key=id.syscall,common_pid.execname:val=hitcount:sort=id,hitcount if id == 16' > \
  1013. /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/trigger
  1014. # cat /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/hist
  1015. # trigger info: hist:keys=id.syscall,common_pid.execname:vals=hitcount:sort=id.syscall,hitcount:size=2048 if id == 16 [active]
  1016. { id: sys_ioctl [ 16], common_pid: gmain [ 2769] } hitcount: 1
  1017. { id: sys_ioctl [ 16], common_pid: evolution-addre [ 8571] } hitcount: 1
  1018. { id: sys_ioctl [ 16], common_pid: gmain [ 3003] } hitcount: 1
  1019. { id: sys_ioctl [ 16], common_pid: gmain [ 2781] } hitcount: 1
  1020. { id: sys_ioctl [ 16], common_pid: gmain [ 2829] } hitcount: 1
  1021. { id: sys_ioctl [ 16], common_pid: bash [ 8726] } hitcount: 1
  1022. { id: sys_ioctl [ 16], common_pid: bash [ 8508] } hitcount: 1
  1023. { id: sys_ioctl [ 16], common_pid: gmain [ 2970] } hitcount: 1
  1024. { id: sys_ioctl [ 16], common_pid: gmain [ 2768] } hitcount: 1
  1025. .
  1026. .
  1027. .
  1028. { id: sys_ioctl [ 16], common_pid: pool [ 8559] } hitcount: 45
  1029. { id: sys_ioctl [ 16], common_pid: pool [ 8555] } hitcount: 48
  1030. { id: sys_ioctl [ 16], common_pid: pool [ 8551] } hitcount: 48
  1031. { id: sys_ioctl [ 16], common_pid: avahi-daemon [ 896] } hitcount: 66
  1032. { id: sys_ioctl [ 16], common_pid: Xorg [ 1267] } hitcount: 26674
  1033. { id: sys_ioctl [ 16], common_pid: compiz [ 2994] } hitcount: 73443
  1034. Totals:
  1035. Hits: 101162
  1036. Entries: 103
  1037. Dropped: 0
  1038. The above output shows that 'compiz' and 'Xorg' are far and away
  1039. the heaviest ioctl callers (which might lead to questions about
  1040. whether they really need to be making all those calls and to
  1041. possible avenues for further investigation.)
  1042. The compound key examples used a key and a sum value (hitcount) to
  1043. sort the output, but we can just as easily use two keys instead.
  1044. Here's an example where we use a compound key composed of the the
  1045. common_pid and size event fields. Sorting with pid as the primary
  1046. key and 'size' as the secondary key allows us to display an
  1047. ordered summary of the recvfrom sizes, with counts, received by
  1048. each process:
  1049. # echo 'hist:key=common_pid.execname,size:val=hitcount:sort=common_pid,size' > \
  1050. /sys/kernel/debug/tracing/events/syscalls/sys_enter_recvfrom/trigger
  1051. # cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_recvfrom/hist
  1052. # trigger info: hist:keys=common_pid.execname,size:vals=hitcount:sort=common_pid.execname,size:size=2048 [active]
  1053. { common_pid: smbd [ 784], size: 4 } hitcount: 1
  1054. { common_pid: dnsmasq [ 1412], size: 4096 } hitcount: 672
  1055. { common_pid: postgres [ 1796], size: 1000 } hitcount: 6
  1056. { common_pid: postgres [ 1867], size: 1000 } hitcount: 10
  1057. { common_pid: bamfdaemon [ 2787], size: 28 } hitcount: 2
  1058. { common_pid: bamfdaemon [ 2787], size: 14360 } hitcount: 1
  1059. { common_pid: compiz [ 2994], size: 8 } hitcount: 1
  1060. { common_pid: compiz [ 2994], size: 20 } hitcount: 11
  1061. { common_pid: gnome-terminal [ 3199], size: 4 } hitcount: 2
  1062. { common_pid: firefox [ 8817], size: 4 } hitcount: 1
  1063. { common_pid: firefox [ 8817], size: 8 } hitcount: 5
  1064. { common_pid: firefox [ 8817], size: 588 } hitcount: 2
  1065. { common_pid: firefox [ 8817], size: 628 } hitcount: 1
  1066. { common_pid: firefox [ 8817], size: 6944 } hitcount: 1
  1067. { common_pid: firefox [ 8817], size: 408880 } hitcount: 2
  1068. { common_pid: firefox [ 8822], size: 8 } hitcount: 2
  1069. { common_pid: firefox [ 8822], size: 160 } hitcount: 2
  1070. { common_pid: firefox [ 8822], size: 320 } hitcount: 2
  1071. { common_pid: firefox [ 8822], size: 352 } hitcount: 1
  1072. .
  1073. .
  1074. .
  1075. { common_pid: pool [ 8923], size: 1960 } hitcount: 10
  1076. { common_pid: pool [ 8923], size: 2048 } hitcount: 10
  1077. { common_pid: pool [ 8924], size: 1960 } hitcount: 10
  1078. { common_pid: pool [ 8924], size: 2048 } hitcount: 10
  1079. { common_pid: pool [ 8928], size: 1964 } hitcount: 4
  1080. { common_pid: pool [ 8928], size: 1965 } hitcount: 2
  1081. { common_pid: pool [ 8928], size: 2048 } hitcount: 6
  1082. { common_pid: pool [ 8929], size: 1982 } hitcount: 1
  1083. { common_pid: pool [ 8929], size: 2048 } hitcount: 1
  1084. Totals:
  1085. Hits: 2016
  1086. Entries: 224
  1087. Dropped: 0
  1088. The above example also illustrates the fact that although a compound
  1089. key is treated as a single entity for hashing purposes, the sub-keys
  1090. it's composed of can be accessed independently.
  1091. The next example uses a string field as the hash key and
  1092. demonstrates how you can manually pause and continue a hist trigger.
  1093. In this example, we'll aggregate fork counts and don't expect a
  1094. large number of entries in the hash table, so we'll drop it to a
  1095. much smaller number, say 256:
  1096. # echo 'hist:key=child_comm:val=hitcount:size=256' > \
  1097. /sys/kernel/debug/tracing/events/sched/sched_process_fork/trigger
  1098. # cat /sys/kernel/debug/tracing/events/sched/sched_process_fork/hist
  1099. # trigger info: hist:keys=child_comm:vals=hitcount:sort=hitcount:size=256 [active]
  1100. { child_comm: dconf worker } hitcount: 1
  1101. { child_comm: ibus-daemon } hitcount: 1
  1102. { child_comm: whoopsie } hitcount: 1
  1103. { child_comm: smbd } hitcount: 1
  1104. { child_comm: gdbus } hitcount: 1
  1105. { child_comm: kthreadd } hitcount: 1
  1106. { child_comm: dconf worker } hitcount: 1
  1107. { child_comm: evolution-alarm } hitcount: 2
  1108. { child_comm: Socket Thread } hitcount: 2
  1109. { child_comm: postgres } hitcount: 2
  1110. { child_comm: bash } hitcount: 3
  1111. { child_comm: compiz } hitcount: 3
  1112. { child_comm: evolution-sourc } hitcount: 4
  1113. { child_comm: dhclient } hitcount: 4
  1114. { child_comm: pool } hitcount: 5
  1115. { child_comm: nm-dispatcher.a } hitcount: 8
  1116. { child_comm: firefox } hitcount: 8
  1117. { child_comm: dbus-daemon } hitcount: 8
  1118. { child_comm: glib-pacrunner } hitcount: 10
  1119. { child_comm: evolution } hitcount: 23
  1120. Totals:
  1121. Hits: 89
  1122. Entries: 20
  1123. Dropped: 0
  1124. If we want to pause the hist trigger, we can simply append :pause to
  1125. the command that started the trigger. Notice that the trigger info
  1126. displays as [paused]:
  1127. # echo 'hist:key=child_comm:val=hitcount:size=256:pause' >> \
  1128. /sys/kernel/debug/tracing/events/sched/sched_process_fork/trigger
  1129. # cat /sys/kernel/debug/tracing/events/sched/sched_process_fork/hist
  1130. # trigger info: hist:keys=child_comm:vals=hitcount:sort=hitcount:size=256 [paused]
  1131. { child_comm: dconf worker } hitcount: 1
  1132. { child_comm: kthreadd } hitcount: 1
  1133. { child_comm: dconf worker } hitcount: 1
  1134. { child_comm: gdbus } hitcount: 1
  1135. { child_comm: ibus-daemon } hitcount: 1
  1136. { child_comm: Socket Thread } hitcount: 2
  1137. { child_comm: evolution-alarm } hitcount: 2
  1138. { child_comm: smbd } hitcount: 2
  1139. { child_comm: bash } hitcount: 3
  1140. { child_comm: whoopsie } hitcount: 3
  1141. { child_comm: compiz } hitcount: 3
  1142. { child_comm: evolution-sourc } hitcount: 4
  1143. { child_comm: pool } hitcount: 5
  1144. { child_comm: postgres } hitcount: 6
  1145. { child_comm: firefox } hitcount: 8
  1146. { child_comm: dhclient } hitcount: 10
  1147. { child_comm: emacs } hitcount: 12
  1148. { child_comm: dbus-daemon } hitcount: 20
  1149. { child_comm: nm-dispatcher.a } hitcount: 20
  1150. { child_comm: evolution } hitcount: 35
  1151. { child_comm: glib-pacrunner } hitcount: 59
  1152. Totals:
  1153. Hits: 199
  1154. Entries: 21
  1155. Dropped: 0
  1156. To manually continue having the trigger aggregate events, append
  1157. :cont instead. Notice that the trigger info displays as [active]
  1158. again, and the data has changed:
  1159. # echo 'hist:key=child_comm:val=hitcount:size=256:cont' >> \
  1160. /sys/kernel/debug/tracing/events/sched/sched_process_fork/trigger
  1161. # cat /sys/kernel/debug/tracing/events/sched/sched_process_fork/hist
  1162. # trigger info: hist:keys=child_comm:vals=hitcount:sort=hitcount:size=256 [active]
  1163. { child_comm: dconf worker } hitcount: 1
  1164. { child_comm: dconf worker } hitcount: 1
  1165. { child_comm: kthreadd } hitcount: 1
  1166. { child_comm: gdbus } hitcount: 1
  1167. { child_comm: ibus-daemon } hitcount: 1
  1168. { child_comm: Socket Thread } hitcount: 2
  1169. { child_comm: evolution-alarm } hitcount: 2
  1170. { child_comm: smbd } hitcount: 2
  1171. { child_comm: whoopsie } hitcount: 3
  1172. { child_comm: compiz } hitcount: 3
  1173. { child_comm: evolution-sourc } hitcount: 4
  1174. { child_comm: bash } hitcount: 5
  1175. { child_comm: pool } hitcount: 5
  1176. { child_comm: postgres } hitcount: 6
  1177. { child_comm: firefox } hitcount: 8
  1178. { child_comm: dhclient } hitcount: 11
  1179. { child_comm: emacs } hitcount: 12
  1180. { child_comm: dbus-daemon } hitcount: 22
  1181. { child_comm: nm-dispatcher.a } hitcount: 22
  1182. { child_comm: evolution } hitcount: 35
  1183. { child_comm: glib-pacrunner } hitcount: 59
  1184. Totals:
  1185. Hits: 206
  1186. Entries: 21
  1187. Dropped: 0
  1188. The previous example showed how to start and stop a hist trigger by
  1189. appending 'pause' and 'continue' to the hist trigger command. A
  1190. hist trigger can also be started in a paused state by initially
  1191. starting the trigger with ':pause' appended. This allows you to
  1192. start the trigger only when you're ready to start collecting data
  1193. and not before. For example, you could start the trigger in a
  1194. paused state, then unpause it and do something you want to measure,
  1195. then pause the trigger again when done.
  1196. Of course, doing this manually can be difficult and error-prone, but
  1197. it is possible to automatically start and stop a hist trigger based
  1198. on some condition, via the enable_hist and disable_hist triggers.
  1199. For example, suppose we wanted to take a look at the relative
  1200. weights in terms of skb length for each callpath that leads to a
  1201. netif_receieve_skb event when downloading a decent-sized file using
  1202. wget.
  1203. First we set up an initially paused stacktrace trigger on the
  1204. netif_receive_skb event:
  1205. # echo 'hist:key=stacktrace:vals=len:pause' > \
  1206. /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
  1207. Next, we set up an 'enable_hist' trigger on the sched_process_exec
  1208. event, with an 'if filename==/usr/bin/wget' filter. The effect of
  1209. this new trigger is that it will 'unpause' the hist trigger we just
  1210. set up on netif_receive_skb if and only if it sees a
  1211. sched_process_exec event with a filename of '/usr/bin/wget'. When
  1212. that happens, all netif_receive_skb events are aggregated into a
  1213. hash table keyed on stacktrace:
  1214. # echo 'enable_hist:net:netif_receive_skb if filename==/usr/bin/wget' > \
  1215. /sys/kernel/debug/tracing/events/sched/sched_process_exec/trigger
  1216. The aggregation continues until the netif_receive_skb is paused
  1217. again, which is what the following disable_hist event does by
  1218. creating a similar setup on the sched_process_exit event, using the
  1219. filter 'comm==wget':
  1220. # echo 'disable_hist:net:netif_receive_skb if comm==wget' > \
  1221. /sys/kernel/debug/tracing/events/sched/sched_process_exit/trigger
  1222. Whenever a process exits and the comm field of the disable_hist
  1223. trigger filter matches 'comm==wget', the netif_receive_skb hist
  1224. trigger is disabled.
  1225. The overall effect is that netif_receive_skb events are aggregated
  1226. into the hash table for only the duration of the wget. Executing a
  1227. wget command and then listing the 'hist' file will display the
  1228. output generated by the wget command:
  1229. $ wget https://www.kernel.org/pub/linux/kernel/v3.x/patch-3.19.xz
  1230. # cat /sys/kernel/debug/tracing/events/net/netif_receive_skb/hist
  1231. # trigger info: hist:keys=stacktrace:vals=len:sort=hitcount:size=2048 [paused]
  1232. { stacktrace:
  1233. __netif_receive_skb_core+0x46d/0x990
  1234. __netif_receive_skb+0x18/0x60
  1235. netif_receive_skb_internal+0x23/0x90
  1236. napi_gro_receive+0xc8/0x100
  1237. ieee80211_deliver_skb+0xd6/0x270 [mac80211]
  1238. ieee80211_rx_handlers+0xccf/0x22f0 [mac80211]
  1239. ieee80211_prepare_and_rx_handle+0x4e7/0xc40 [mac80211]
  1240. ieee80211_rx+0x31d/0x900 [mac80211]
  1241. iwlagn_rx_reply_rx+0x3db/0x6f0 [iwldvm]
  1242. iwl_rx_dispatch+0x8e/0xf0 [iwldvm]
  1243. iwl_pcie_irq_handler+0xe3c/0x12f0 [iwlwifi]
  1244. irq_thread_fn+0x20/0x50
  1245. irq_thread+0x11f/0x150
  1246. kthread+0xd2/0xf0
  1247. ret_from_fork+0x42/0x70
  1248. } hitcount: 85 len: 28884
  1249. { stacktrace:
  1250. __netif_receive_skb_core+0x46d/0x990
  1251. __netif_receive_skb+0x18/0x60
  1252. netif_receive_skb_internal+0x23/0x90
  1253. napi_gro_complete+0xa4/0xe0
  1254. dev_gro_receive+0x23a/0x360
  1255. napi_gro_receive+0x30/0x100
  1256. ieee80211_deliver_skb+0xd6/0x270 [mac80211]
  1257. ieee80211_rx_handlers+0xccf/0x22f0 [mac80211]
  1258. ieee80211_prepare_and_rx_handle+0x4e7/0xc40 [mac80211]
  1259. ieee80211_rx+0x31d/0x900 [mac80211]
  1260. iwlagn_rx_reply_rx+0x3db/0x6f0 [iwldvm]
  1261. iwl_rx_dispatch+0x8e/0xf0 [iwldvm]
  1262. iwl_pcie_irq_handler+0xe3c/0x12f0 [iwlwifi]
  1263. irq_thread_fn+0x20/0x50
  1264. irq_thread+0x11f/0x150
  1265. kthread+0xd2/0xf0
  1266. } hitcount: 98 len: 664329
  1267. { stacktrace:
  1268. __netif_receive_skb_core+0x46d/0x990
  1269. __netif_receive_skb+0x18/0x60
  1270. process_backlog+0xa8/0x150
  1271. net_rx_action+0x15d/0x340
  1272. __do_softirq+0x114/0x2c0
  1273. do_softirq_own_stack+0x1c/0x30
  1274. do_softirq+0x65/0x70
  1275. __local_bh_enable_ip+0xb5/0xc0
  1276. ip_finish_output+0x1f4/0x840
  1277. ip_output+0x6b/0xc0
  1278. ip_local_out_sk+0x31/0x40
  1279. ip_send_skb+0x1a/0x50
  1280. udp_send_skb+0x173/0x2a0
  1281. udp_sendmsg+0x2bf/0x9f0
  1282. inet_sendmsg+0x64/0xa0
  1283. sock_sendmsg+0x3d/0x50
  1284. } hitcount: 115 len: 13030
  1285. { stacktrace:
  1286. __netif_receive_skb_core+0x46d/0x990
  1287. __netif_receive_skb+0x18/0x60
  1288. netif_receive_skb_internal+0x23/0x90
  1289. napi_gro_complete+0xa4/0xe0
  1290. napi_gro_flush+0x6d/0x90
  1291. iwl_pcie_irq_handler+0x92a/0x12f0 [iwlwifi]
  1292. irq_thread_fn+0x20/0x50
  1293. irq_thread+0x11f/0x150
  1294. kthread+0xd2/0xf0
  1295. ret_from_fork+0x42/0x70
  1296. } hitcount: 934 len: 5512212
  1297. Totals:
  1298. Hits: 1232
  1299. Entries: 4
  1300. Dropped: 0
  1301. The above shows all the netif_receive_skb callpaths and their total
  1302. lengths for the duration of the wget command.
  1303. The 'clear' hist trigger param can be used to clear the hash table.
  1304. Suppose we wanted to try another run of the previous example but
  1305. this time also wanted to see the complete list of events that went
  1306. into the histogram. In order to avoid having to set everything up
  1307. again, we can just clear the histogram first:
  1308. # echo 'hist:key=stacktrace:vals=len:clear' >> \
  1309. /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
  1310. Just to verify that it is in fact cleared, here's what we now see in
  1311. the hist file:
  1312. # cat /sys/kernel/debug/tracing/events/net/netif_receive_skb/hist
  1313. # trigger info: hist:keys=stacktrace:vals=len:sort=hitcount:size=2048 [paused]
  1314. Totals:
  1315. Hits: 0
  1316. Entries: 0
  1317. Dropped: 0
  1318. Since we want to see the detailed list of every netif_receive_skb
  1319. event occurring during the new run, which are in fact the same
  1320. events being aggregated into the hash table, we add some additional
  1321. 'enable_event' events to the triggering sched_process_exec and
  1322. sched_process_exit events as such:
  1323. # echo 'enable_event:net:netif_receive_skb if filename==/usr/bin/wget' > \
  1324. /sys/kernel/debug/tracing/events/sched/sched_process_exec/trigger
  1325. # echo 'disable_event:net:netif_receive_skb if comm==wget' > \
  1326. /sys/kernel/debug/tracing/events/sched/sched_process_exit/trigger
  1327. If you read the trigger files for the sched_process_exec and
  1328. sched_process_exit triggers, you should see two triggers for each:
  1329. one enabling/disabling the hist aggregation and the other
  1330. enabling/disabling the logging of events:
  1331. # cat /sys/kernel/debug/tracing/events/sched/sched_process_exec/trigger
  1332. enable_event:net:netif_receive_skb:unlimited if filename==/usr/bin/wget
  1333. enable_hist:net:netif_receive_skb:unlimited if filename==/usr/bin/wget
  1334. # cat /sys/kernel/debug/tracing/events/sched/sched_process_exit/trigger
  1335. enable_event:net:netif_receive_skb:unlimited if comm==wget
  1336. disable_hist:net:netif_receive_skb:unlimited if comm==wget
  1337. In other words, whenever either of the sched_process_exec or
  1338. sched_process_exit events is hit and matches 'wget', it enables or
  1339. disables both the histogram and the event log, and what you end up
  1340. with is a hash table and set of events just covering the specified
  1341. duration. Run the wget command again:
  1342. $ wget https://www.kernel.org/pub/linux/kernel/v3.x/patch-3.19.xz
  1343. Displaying the 'hist' file should show something similar to what you
  1344. saw in the last run, but this time you should also see the
  1345. individual events in the trace file:
  1346. # cat /sys/kernel/debug/tracing/trace
  1347. # tracer: nop
  1348. #
  1349. # entries-in-buffer/entries-written: 183/1426 #P:4
  1350. #
  1351. # _-----=> irqs-off
  1352. # / _----=> need-resched
  1353. # | / _---=> hardirq/softirq
  1354. # || / _--=> preempt-depth
  1355. # ||| / delay
  1356. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  1357. # | | | |||| | |
  1358. wget-15108 [000] ..s1 31769.606929: netif_receive_skb: dev=lo skbaddr=ffff88009c353100 len=60
  1359. wget-15108 [000] ..s1 31769.606999: netif_receive_skb: dev=lo skbaddr=ffff88009c353200 len=60
  1360. dnsmasq-1382 [000] ..s1 31769.677652: netif_receive_skb: dev=lo skbaddr=ffff88009c352b00 len=130
  1361. dnsmasq-1382 [000] ..s1 31769.685917: netif_receive_skb: dev=lo skbaddr=ffff88009c352200 len=138
  1362. ##### CPU 2 buffer started ####
  1363. irq/29-iwlwifi-559 [002] ..s. 31772.031529: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d433d00 len=2948
  1364. irq/29-iwlwifi-559 [002] ..s. 31772.031572: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d432200 len=1500
  1365. irq/29-iwlwifi-559 [002] ..s. 31772.032196: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d433100 len=2948
  1366. irq/29-iwlwifi-559 [002] ..s. 31772.032761: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d433000 len=2948
  1367. irq/29-iwlwifi-559 [002] ..s. 31772.033220: netif_receive_skb: dev=wlan0 skbaddr=ffff88009d432e00 len=1500
  1368. .
  1369. .
  1370. .
  1371. The following example demonstrates how multiple hist triggers can be
  1372. attached to a given event. This capability can be useful for
  1373. creating a set of different summaries derived from the same set of
  1374. events, or for comparing the effects of different filters, among
  1375. other things.
  1376. # echo 'hist:keys=skbaddr.hex:vals=len if len < 0' >> \
  1377. /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
  1378. # echo 'hist:keys=skbaddr.hex:vals=len if len > 4096' >> \
  1379. /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
  1380. # echo 'hist:keys=skbaddr.hex:vals=len if len == 256' >> \
  1381. /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
  1382. # echo 'hist:keys=skbaddr.hex:vals=len' >> \
  1383. /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
  1384. # echo 'hist:keys=len:vals=common_preempt_count' >> \
  1385. /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
  1386. The above set of commands create four triggers differing only in
  1387. their filters, along with a completely different though fairly
  1388. nonsensical trigger. Note that in order to append multiple hist
  1389. triggers to the same file, you should use the '>>' operator to
  1390. append them ('>' will also add the new hist trigger, but will remove
  1391. any existing hist triggers beforehand).
  1392. Displaying the contents of the 'hist' file for the event shows the
  1393. contents of all five histograms:
  1394. # cat /sys/kernel/debug/tracing/events/net/netif_receive_skb/hist
  1395. # event histogram
  1396. #
  1397. # trigger info: hist:keys=len:vals=hitcount,common_preempt_count:sort=hitcount:size=2048 [active]
  1398. #
  1399. { len: 176 } hitcount: 1 common_preempt_count: 0
  1400. { len: 223 } hitcount: 1 common_preempt_count: 0
  1401. { len: 4854 } hitcount: 1 common_preempt_count: 0
  1402. { len: 395 } hitcount: 1 common_preempt_count: 0
  1403. { len: 177 } hitcount: 1 common_preempt_count: 0
  1404. { len: 446 } hitcount: 1 common_preempt_count: 0
  1405. { len: 1601 } hitcount: 1 common_preempt_count: 0
  1406. .
  1407. .
  1408. .
  1409. { len: 1280 } hitcount: 66 common_preempt_count: 0
  1410. { len: 116 } hitcount: 81 common_preempt_count: 40
  1411. { len: 708 } hitcount: 112 common_preempt_count: 0
  1412. { len: 46 } hitcount: 221 common_preempt_count: 0
  1413. { len: 1264 } hitcount: 458 common_preempt_count: 0
  1414. Totals:
  1415. Hits: 1428
  1416. Entries: 147
  1417. Dropped: 0
  1418. # event histogram
  1419. #
  1420. # trigger info: hist:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 [active]
  1421. #
  1422. { skbaddr: ffff8800baee5e00 } hitcount: 1 len: 130
  1423. { skbaddr: ffff88005f3d5600 } hitcount: 1 len: 1280
  1424. { skbaddr: ffff88005f3d4900 } hitcount: 1 len: 1280
  1425. { skbaddr: ffff88009fed6300 } hitcount: 1 len: 115
  1426. { skbaddr: ffff88009fe0ad00 } hitcount: 1 len: 115
  1427. { skbaddr: ffff88008cdb1900 } hitcount: 1 len: 46
  1428. { skbaddr: ffff880064b5ef00 } hitcount: 1 len: 118
  1429. { skbaddr: ffff880044e3c700 } hitcount: 1 len: 60
  1430. { skbaddr: ffff880100065900 } hitcount: 1 len: 46
  1431. { skbaddr: ffff8800d46bd500 } hitcount: 1 len: 116
  1432. { skbaddr: ffff88005f3d5f00 } hitcount: 1 len: 1280
  1433. { skbaddr: ffff880100064700 } hitcount: 1 len: 365
  1434. { skbaddr: ffff8800badb6f00 } hitcount: 1 len: 60
  1435. .
  1436. .
  1437. .
  1438. { skbaddr: ffff88009fe0be00 } hitcount: 27 len: 24677
  1439. { skbaddr: ffff88009fe0a400 } hitcount: 27 len: 23052
  1440. { skbaddr: ffff88009fe0b700 } hitcount: 31 len: 25589
  1441. { skbaddr: ffff88009fe0b600 } hitcount: 32 len: 27326
  1442. { skbaddr: ffff88006a462800 } hitcount: 68 len: 71678
  1443. { skbaddr: ffff88006a463700 } hitcount: 70 len: 72678
  1444. { skbaddr: ffff88006a462b00 } hitcount: 71 len: 77589
  1445. { skbaddr: ffff88006a463600 } hitcount: 73 len: 71307
  1446. { skbaddr: ffff88006a462200 } hitcount: 81 len: 81032
  1447. Totals:
  1448. Hits: 1451
  1449. Entries: 318
  1450. Dropped: 0
  1451. # event histogram
  1452. #
  1453. # trigger info: hist:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 if len == 256 [active]
  1454. #
  1455. Totals:
  1456. Hits: 0
  1457. Entries: 0
  1458. Dropped: 0
  1459. # event histogram
  1460. #
  1461. # trigger info: hist:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 if len > 4096 [active]
  1462. #
  1463. { skbaddr: ffff88009fd2c300 } hitcount: 1 len: 7212
  1464. { skbaddr: ffff8800d2bcce00 } hitcount: 1 len: 7212
  1465. { skbaddr: ffff8800d2bcd700 } hitcount: 1 len: 7212
  1466. { skbaddr: ffff8800d2bcda00 } hitcount: 1 len: 21492
  1467. { skbaddr: ffff8800ae2e2d00 } hitcount: 1 len: 7212
  1468. { skbaddr: ffff8800d2bcdb00 } hitcount: 1 len: 7212
  1469. { skbaddr: ffff88006a4df500 } hitcount: 1 len: 4854
  1470. { skbaddr: ffff88008ce47b00 } hitcount: 1 len: 18636
  1471. { skbaddr: ffff8800ae2e2200 } hitcount: 1 len: 12924
  1472. { skbaddr: ffff88005f3e1000 } hitcount: 1 len: 4356
  1473. { skbaddr: ffff8800d2bcdc00 } hitcount: 2 len: 24420
  1474. { skbaddr: ffff8800d2bcc200 } hitcount: 2 len: 12996
  1475. Totals:
  1476. Hits: 14
  1477. Entries: 12
  1478. Dropped: 0
  1479. # event histogram
  1480. #
  1481. # trigger info: hist:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 if len < 0 [active]
  1482. #
  1483. Totals:
  1484. Hits: 0
  1485. Entries: 0
  1486. Dropped: 0
  1487. Named triggers can be used to have triggers share a common set of
  1488. histogram data. This capability is mostly useful for combining the
  1489. output of events generated by tracepoints contained inside inline
  1490. functions, but names can be used in a hist trigger on any event.
  1491. For example, these two triggers when hit will update the same 'len'
  1492. field in the shared 'foo' histogram data:
  1493. # echo 'hist:name=foo:keys=skbaddr.hex:vals=len' > \
  1494. /sys/kernel/debug/tracing/events/net/netif_receive_skb/trigger
  1495. # echo 'hist:name=foo:keys=skbaddr.hex:vals=len' > \
  1496. /sys/kernel/debug/tracing/events/net/netif_rx/trigger
  1497. You can see that they're updating common histogram data by reading
  1498. each event's hist files at the same time:
  1499. # cat /sys/kernel/debug/tracing/events/net/netif_receive_skb/hist;
  1500. cat /sys/kernel/debug/tracing/events/net/netif_rx/hist
  1501. # event histogram
  1502. #
  1503. # trigger info: hist:name=foo:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 [active]
  1504. #
  1505. { skbaddr: ffff88000ad53500 } hitcount: 1 len: 46
  1506. { skbaddr: ffff8800af5a1500 } hitcount: 1 len: 76
  1507. { skbaddr: ffff8800d62a1900 } hitcount: 1 len: 46
  1508. { skbaddr: ffff8800d2bccb00 } hitcount: 1 len: 468
  1509. { skbaddr: ffff8800d3c69900 } hitcount: 1 len: 46
  1510. { skbaddr: ffff88009ff09100 } hitcount: 1 len: 52
  1511. { skbaddr: ffff88010f13ab00 } hitcount: 1 len: 168
  1512. { skbaddr: ffff88006a54f400 } hitcount: 1 len: 46
  1513. { skbaddr: ffff8800d2bcc500 } hitcount: 1 len: 260
  1514. { skbaddr: ffff880064505000 } hitcount: 1 len: 46
  1515. { skbaddr: ffff8800baf24e00 } hitcount: 1 len: 32
  1516. { skbaddr: ffff88009fe0ad00 } hitcount: 1 len: 46
  1517. { skbaddr: ffff8800d3edff00 } hitcount: 1 len: 44
  1518. { skbaddr: ffff88009fe0b400 } hitcount: 1 len: 168
  1519. { skbaddr: ffff8800a1c55a00 } hitcount: 1 len: 40
  1520. { skbaddr: ffff8800d2bcd100 } hitcount: 1 len: 40
  1521. { skbaddr: ffff880064505f00 } hitcount: 1 len: 174
  1522. { skbaddr: ffff8800a8bff200 } hitcount: 1 len: 160
  1523. { skbaddr: ffff880044e3cc00 } hitcount: 1 len: 76
  1524. { skbaddr: ffff8800a8bfe700 } hitcount: 1 len: 46
  1525. { skbaddr: ffff8800d2bcdc00 } hitcount: 1 len: 32
  1526. { skbaddr: ffff8800a1f64800 } hitcount: 1 len: 46
  1527. { skbaddr: ffff8800d2bcde00 } hitcount: 1 len: 988
  1528. { skbaddr: ffff88006a5dea00 } hitcount: 1 len: 46
  1529. { skbaddr: ffff88002e37a200 } hitcount: 1 len: 44
  1530. { skbaddr: ffff8800a1f32c00 } hitcount: 2 len: 676
  1531. { skbaddr: ffff88000ad52600 } hitcount: 2 len: 107
  1532. { skbaddr: ffff8800a1f91e00 } hitcount: 2 len: 92
  1533. { skbaddr: ffff8800af5a0200 } hitcount: 2 len: 142
  1534. { skbaddr: ffff8800d2bcc600 } hitcount: 2 len: 220
  1535. { skbaddr: ffff8800ba36f500 } hitcount: 2 len: 92
  1536. { skbaddr: ffff8800d021f800 } hitcount: 2 len: 92
  1537. { skbaddr: ffff8800a1f33600 } hitcount: 2 len: 675
  1538. { skbaddr: ffff8800a8bfff00 } hitcount: 3 len: 138
  1539. { skbaddr: ffff8800d62a1300 } hitcount: 3 len: 138
  1540. { skbaddr: ffff88002e37a100 } hitcount: 4 len: 184
  1541. { skbaddr: ffff880064504400 } hitcount: 4 len: 184
  1542. { skbaddr: ffff8800a8bfec00 } hitcount: 4 len: 184
  1543. { skbaddr: ffff88000ad53700 } hitcount: 5 len: 230
  1544. { skbaddr: ffff8800d2bcdb00 } hitcount: 5 len: 196
  1545. { skbaddr: ffff8800a1f90000 } hitcount: 6 len: 276
  1546. { skbaddr: ffff88006a54f900 } hitcount: 6 len: 276
  1547. Totals:
  1548. Hits: 81
  1549. Entries: 42
  1550. Dropped: 0
  1551. # event histogram
  1552. #
  1553. # trigger info: hist:name=foo:keys=skbaddr.hex:vals=hitcount,len:sort=hitcount:size=2048 [active]
  1554. #
  1555. { skbaddr: ffff88000ad53500 } hitcount: 1 len: 46
  1556. { skbaddr: ffff8800af5a1500 } hitcount: 1 len: 76
  1557. { skbaddr: ffff8800d62a1900 } hitcount: 1 len: 46
  1558. { skbaddr: ffff8800d2bccb00 } hitcount: 1 len: 468
  1559. { skbaddr: ffff8800d3c69900 } hitcount: 1 len: 46
  1560. { skbaddr: ffff88009ff09100 } hitcount: 1 len: 52
  1561. { skbaddr: ffff88010f13ab00 } hitcount: 1 len: 168
  1562. { skbaddr: ffff88006a54f400 } hitcount: 1 len: 46
  1563. { skbaddr: ffff8800d2bcc500 } hitcount: 1 len: 260
  1564. { skbaddr: ffff880064505000 } hitcount: 1 len: 46
  1565. { skbaddr: ffff8800baf24e00 } hitcount: 1 len: 32
  1566. { skbaddr: ffff88009fe0ad00 } hitcount: 1 len: 46
  1567. { skbaddr: ffff8800d3edff00 } hitcount: 1 len: 44
  1568. { skbaddr: ffff88009fe0b400 } hitcount: 1 len: 168
  1569. { skbaddr: ffff8800a1c55a00 } hitcount: 1 len: 40
  1570. { skbaddr: ffff8800d2bcd100 } hitcount: 1 len: 40
  1571. { skbaddr: ffff880064505f00 } hitcount: 1 len: 174
  1572. { skbaddr: ffff8800a8bff200 } hitcount: 1 len: 160
  1573. { skbaddr: ffff880044e3cc00 } hitcount: 1 len: 76
  1574. { skbaddr: ffff8800a8bfe700 } hitcount: 1 len: 46
  1575. { skbaddr: ffff8800d2bcdc00 } hitcount: 1 len: 32
  1576. { skbaddr: ffff8800a1f64800 } hitcount: 1 len: 46
  1577. { skbaddr: ffff8800d2bcde00 } hitcount: 1 len: 988
  1578. { skbaddr: ffff88006a5dea00 } hitcount: 1 len: 46
  1579. { skbaddr: ffff88002e37a200 } hitcount: 1 len: 44
  1580. { skbaddr: ffff8800a1f32c00 } hitcount: 2 len: 676
  1581. { skbaddr: ffff88000ad52600 } hitcount: 2 len: 107
  1582. { skbaddr: ffff8800a1f91e00 } hitcount: 2 len: 92
  1583. { skbaddr: ffff8800af5a0200 } hitcount: 2 len: 142
  1584. { skbaddr: ffff8800d2bcc600 } hitcount: 2 len: 220
  1585. { skbaddr: ffff8800ba36f500 } hitcount: 2 len: 92
  1586. { skbaddr: ffff8800d021f800 } hitcount: 2 len: 92
  1587. { skbaddr: ffff8800a1f33600 } hitcount: 2 len: 675
  1588. { skbaddr: ffff8800a8bfff00 } hitcount: 3 len: 138
  1589. { skbaddr: ffff8800d62a1300 } hitcount: 3 len: 138
  1590. { skbaddr: ffff88002e37a100 } hitcount: 4 len: 184
  1591. { skbaddr: ffff880064504400 } hitcount: 4 len: 184
  1592. { skbaddr: ffff8800a8bfec00 } hitcount: 4 len: 184
  1593. { skbaddr: ffff88000ad53700 } hitcount: 5 len: 230
  1594. { skbaddr: ffff8800d2bcdb00 } hitcount: 5 len: 196
  1595. { skbaddr: ffff8800a1f90000 } hitcount: 6 len: 276
  1596. { skbaddr: ffff88006a54f900 } hitcount: 6 len: 276
  1597. Totals:
  1598. Hits: 81
  1599. Entries: 42
  1600. Dropped: 0
  1601. And here's an example that shows how to combine histogram data from
  1602. any two events even if they don't share any 'compatible' fields
  1603. other than 'hitcount' and 'stacktrace'. These commands create a
  1604. couple of triggers named 'bar' using those fields:
  1605. # echo 'hist:name=bar:key=stacktrace:val=hitcount' > \
  1606. /sys/kernel/debug/tracing/events/sched/sched_process_fork/trigger
  1607. # echo 'hist:name=bar:key=stacktrace:val=hitcount' > \
  1608. /sys/kernel/debug/tracing/events/net/netif_rx/trigger
  1609. And displaying the output of either shows some interesting if
  1610. somewhat confusing output:
  1611. # cat /sys/kernel/debug/tracing/events/sched/sched_process_fork/hist
  1612. # cat /sys/kernel/debug/tracing/events/net/netif_rx/hist
  1613. # event histogram
  1614. #
  1615. # trigger info: hist:name=bar:keys=stacktrace:vals=hitcount:sort=hitcount:size=2048 [active]
  1616. #
  1617. { stacktrace:
  1618. _do_fork+0x18e/0x330
  1619. kernel_thread+0x29/0x30
  1620. kthreadd+0x154/0x1b0
  1621. ret_from_fork+0x3f/0x70
  1622. } hitcount: 1
  1623. { stacktrace:
  1624. netif_rx_internal+0xb2/0xd0
  1625. netif_rx_ni+0x20/0x70
  1626. dev_loopback_xmit+0xaa/0xd0
  1627. ip_mc_output+0x126/0x240
  1628. ip_local_out_sk+0x31/0x40
  1629. igmp_send_report+0x1e9/0x230
  1630. igmp_timer_expire+0xe9/0x120
  1631. call_timer_fn+0x39/0xf0
  1632. run_timer_softirq+0x1e1/0x290
  1633. __do_softirq+0xfd/0x290
  1634. irq_exit+0x98/0xb0
  1635. smp_apic_timer_interrupt+0x4a/0x60
  1636. apic_timer_interrupt+0x6d/0x80
  1637. cpuidle_enter+0x17/0x20
  1638. call_cpuidle+0x3b/0x60
  1639. cpu_startup_entry+0x22d/0x310
  1640. } hitcount: 1
  1641. { stacktrace:
  1642. netif_rx_internal+0xb2/0xd0
  1643. netif_rx_ni+0x20/0x70
  1644. dev_loopback_xmit+0xaa/0xd0
  1645. ip_mc_output+0x17f/0x240
  1646. ip_local_out_sk+0x31/0x40
  1647. ip_send_skb+0x1a/0x50
  1648. udp_send_skb+0x13e/0x270
  1649. udp_sendmsg+0x2bf/0x980
  1650. inet_sendmsg+0x67/0xa0
  1651. sock_sendmsg+0x38/0x50
  1652. SYSC_sendto+0xef/0x170
  1653. SyS_sendto+0xe/0x10
  1654. entry_SYSCALL_64_fastpath+0x12/0x6a
  1655. } hitcount: 2
  1656. { stacktrace:
  1657. netif_rx_internal+0xb2/0xd0
  1658. netif_rx+0x1c/0x60
  1659. loopback_xmit+0x6c/0xb0
  1660. dev_hard_start_xmit+0x219/0x3a0
  1661. __dev_queue_xmit+0x415/0x4f0
  1662. dev_queue_xmit_sk+0x13/0x20
  1663. ip_finish_output2+0x237/0x340
  1664. ip_finish_output+0x113/0x1d0
  1665. ip_output+0x66/0xc0
  1666. ip_local_out_sk+0x31/0x40
  1667. ip_send_skb+0x1a/0x50
  1668. udp_send_skb+0x16d/0x270
  1669. udp_sendmsg+0x2bf/0x980
  1670. inet_sendmsg+0x67/0xa0
  1671. sock_sendmsg+0x38/0x50
  1672. ___sys_sendmsg+0x14e/0x270
  1673. } hitcount: 76
  1674. { stacktrace:
  1675. netif_rx_internal+0xb2/0xd0
  1676. netif_rx+0x1c/0x60
  1677. loopback_xmit+0x6c/0xb0
  1678. dev_hard_start_xmit+0x219/0x3a0
  1679. __dev_queue_xmit+0x415/0x4f0
  1680. dev_queue_xmit_sk+0x13/0x20
  1681. ip_finish_output2+0x237/0x340
  1682. ip_finish_output+0x113/0x1d0
  1683. ip_output+0x66/0xc0
  1684. ip_local_out_sk+0x31/0x40
  1685. ip_send_skb+0x1a/0x50
  1686. udp_send_skb+0x16d/0x270
  1687. udp_sendmsg+0x2bf/0x980
  1688. inet_sendmsg+0x67/0xa0
  1689. sock_sendmsg+0x38/0x50
  1690. ___sys_sendmsg+0x269/0x270
  1691. } hitcount: 77
  1692. { stacktrace:
  1693. netif_rx_internal+0xb2/0xd0
  1694. netif_rx+0x1c/0x60
  1695. loopback_xmit+0x6c/0xb0
  1696. dev_hard_start_xmit+0x219/0x3a0
  1697. __dev_queue_xmit+0x415/0x4f0
  1698. dev_queue_xmit_sk+0x13/0x20
  1699. ip_finish_output2+0x237/0x340
  1700. ip_finish_output+0x113/0x1d0
  1701. ip_output+0x66/0xc0
  1702. ip_local_out_sk+0x31/0x40
  1703. ip_send_skb+0x1a/0x50
  1704. udp_send_skb+0x16d/0x270
  1705. udp_sendmsg+0x2bf/0x980
  1706. inet_sendmsg+0x67/0xa0
  1707. sock_sendmsg+0x38/0x50
  1708. SYSC_sendto+0xef/0x170
  1709. } hitcount: 88
  1710. { stacktrace:
  1711. _do_fork+0x18e/0x330
  1712. SyS_clone+0x19/0x20
  1713. entry_SYSCALL_64_fastpath+0x12/0x6a
  1714. } hitcount: 244
  1715. Totals:
  1716. Hits: 489
  1717. Entries: 7
  1718. Dropped: 0