usage.rst 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. .. highlight:: shell
  3. ***************************************************************
  4. Basic Usage (with examples) for each of the Yocto Tracing Tools
  5. ***************************************************************
  6. |
  7. This chapter presents basic usage examples for each of the tracing
  8. tools.
  9. perf
  10. ====
  11. The perf tool is the profiling and tracing tool that comes bundled
  12. with the Linux kernel.
  13. Don't let the fact that it's part of the kernel fool you into thinking
  14. that it's only for tracing and profiling the kernel --- you can indeed use
  15. it to trace and profile just the kernel, but you can also use it to
  16. profile specific applications separately (with or without kernel
  17. context), and you can also use it to trace and profile the kernel and
  18. all applications on the system simultaneously to gain a system-wide view
  19. of what's going on.
  20. In many ways, perf aims to be a superset of all the tracing and
  21. profiling tools available in Linux today, including all the other tools
  22. covered in this How-to. The past couple of years have seen perf subsume a
  23. lot of the functionality of those other tools and, at the same time,
  24. those other tools have removed large portions of their previous
  25. functionality and replaced it with calls to the equivalent functionality
  26. now implemented by the perf subsystem. Extrapolation suggests that at
  27. some point those other tools will become completely redundant and
  28. go away; until then, we'll cover those other tools in these pages and in
  29. many cases show how the same things can be accomplished in perf and the
  30. other tools when it seems useful to do so.
  31. The coverage below details some of the most common ways you'll likely
  32. want to apply the tool; full documentation can be found either within
  33. the tool itself or in the manual pages at
  34. `perf(1) <https://linux.die.net/man/1/perf>`__.
  35. perf Setup
  36. ----------
  37. For this section, we'll assume you've already performed the basic setup
  38. outlined in the ":ref:`profile-manual/intro:General Setup`" section.
  39. In particular, you'll get the most mileage out of perf if you profile an
  40. image built with the following in your ``local.conf`` file::
  41. INHIBIT_PACKAGE_STRIP = "1"
  42. perf runs on the target system for the most part. You can archive
  43. profile data and copy it to the host for analysis, but for the rest of
  44. this document we assume you're connected to the host through SSH and will be
  45. running the perf commands on the target.
  46. Basic perf Usage
  47. ----------------
  48. The perf tool is pretty much self-documenting. To remind yourself of the
  49. available commands, just type ``perf``, which will show you basic usage
  50. along with the available perf subcommands::
  51. root@crownbay:~# perf
  52. usage: perf [--version] [--help] COMMAND [ARGS]
  53. The most commonly used perf commands are:
  54. annotate Read perf.data (created by perf record) and display annotated code
  55. archive Create archive with object files with build-ids found in perf.data file
  56. bench General framework for benchmark suites
  57. buildid-cache Manage build-id cache.
  58. buildid-list List the buildids in a perf.data file
  59. diff Read two perf.data files and display the differential profile
  60. evlist List the event names in a perf.data file
  61. inject Filter to augment the events stream with additional information
  62. kmem Tool to trace/measure kernel memory(slab) properties
  63. kvm Tool to trace/measure kvm guest os
  64. list List all symbolic event types
  65. lock Analyze lock events
  66. probe Define new dynamic tracepoints
  67. record Run a command and record its profile into perf.data
  68. report Read perf.data (created by perf record) and display the profile
  69. sched Tool to trace/measure scheduler properties (latencies)
  70. script Read perf.data (created by perf record) and display trace output
  71. stat Run a command and gather performance counter statistics
  72. test Runs sanity tests.
  73. timechart Tool to visualize total system behavior during a workload
  74. top System profiling tool.
  75. See 'perf help COMMAND' for more information on a specific command.
  76. Using perf to do Basic Profiling
  77. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. As a simple test case, we'll profile the ``wget`` of a fairly large file,
  79. which is a minimally interesting case because it has both file and
  80. network I/O aspects, and at least in the case of standard Yocto images,
  81. it's implemented as part of BusyBox, so the methods we use to analyze it
  82. can be used in a similar way to the whole host of supported BusyBox
  83. applets in Yocto::
  84. root@crownbay:~# rm linux-2.6.19.2.tar.bz2; \
  85. wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2
  86. The quickest and easiest way to get some basic overall data about what's
  87. going on for a particular workload is to profile it using ``perf stat``.
  88. This command basically profiles using a few default counters and displays
  89. the summed counts at the end of the run::
  90. root@crownbay:~# perf stat wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2
  91. Connecting to downloads.yoctoproject.org (140.211.169.59:80)
  92. linux-2.6.19.2.tar.b 100% |***************************************************| 41727k 0:00:00 ETA
  93. Performance counter stats for 'wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2':
  94. 4597.223902 task-clock # 0.077 CPUs utilized
  95. 23568 context-switches # 0.005 M/sec
  96. 68 CPU-migrations # 0.015 K/sec
  97. 241 page-faults # 0.052 K/sec
  98. 3045817293 cycles # 0.663 GHz
  99. <not supported> stalled-cycles-frontend
  100. <not supported> stalled-cycles-backend
  101. 858909167 instructions # 0.28 insns per cycle
  102. 165441165 branches # 35.987 M/sec
  103. 19550329 branch-misses # 11.82% of all branches
  104. 59.836627620 seconds time elapsed
  105. Such a simple-minded test doesn't always yield much of interest, but sometimes
  106. it does (see the :yocto_bugs:`Slow write speed on live images with denzil
  107. </show_bug.cgi?id=3049>` bug report).
  108. Also, note that ``perf stat`` isn't restricted to a fixed set of counters
  109. --- basically any event listed in the output of ``perf list`` can be tallied
  110. by ``perf stat``. For example, suppose we wanted to see a summary of all
  111. the events related to kernel memory allocation/freeing along with cache
  112. hits and misses::
  113. root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2
  114. Connecting to downloads.yoctoproject.org (140.211.169.59:80)
  115. linux-2.6.19.2.tar.b 100% |***************************************************| 41727k 0:00:00 ETA
  116. Performance counter stats for 'wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2':
  117. 5566 kmem:kmalloc
  118. 125517 kmem:kmem_cache_alloc
  119. 0 kmem:kmalloc_node
  120. 0 kmem:kmem_cache_alloc_node
  121. 34401 kmem:kfree
  122. 69920 kmem:kmem_cache_free
  123. 133 kmem:mm_page_free
  124. 41 kmem:mm_page_free_batched
  125. 11502 kmem:mm_page_alloc
  126. 11375 kmem:mm_page_alloc_zone_locked
  127. 0 kmem:mm_page_pcpu_drain
  128. 0 kmem:mm_page_alloc_extfrag
  129. 66848602 cache-references
  130. 2917740 cache-misses # 4.365 % of all cache refs
  131. 44.831023415 seconds time elapsed
  132. As you can see, ``perf stat`` gives us a nice easy
  133. way to get a quick overview of what might be happening for a set of
  134. events, but normally we'd need a little more detail in order to
  135. understand what's going on in a way that we can act on in a useful way.
  136. To dive down into a next level of detail, we can use ``perf record`` /
  137. ``perf report`` which will collect profiling data and present it to use using an
  138. interactive text-based UI (or just as text if we specify ``--stdio`` to
  139. ``perf report``).
  140. As our first attempt at profiling this workload, we'll just run ``perf
  141. record``, handing it the workload we want to profile (everything after
  142. ``perf record`` and any perf options we hand it --- here none, will be
  143. executed in a new shell). perf collects samples until the process exits
  144. and records them in a file named ``perf.data`` in the current working
  145. directory::
  146. root@crownbay:~# perf record wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2
  147. Connecting to downloads.yoctoproject.org (140.211.169.59:80)
  148. linux-2.6.19.2.tar.b 100% |************************************************| 41727k 0:00:00 ETA
  149. [ perf record: Woken up 1 times to write data ]
  150. [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]
  151. To see the results in a
  152. "text-based UI" (tui), just run ``perf report``, which will read the
  153. perf.data file in the current working directory and display the results
  154. in an interactive UI::
  155. root@crownbay:~# perf report
  156. .. image:: figures/perf-wget-flat-stripped.png
  157. :align: center
  158. :width: 70%
  159. The above screenshot displays a "flat" profile, one entry for each
  160. "bucket" corresponding to the functions that were profiled during the
  161. profiling run, ordered from the most popular to the least (perf has
  162. options to sort in various orders and keys as well as display entries
  163. only above a certain threshold and so on --- see the perf documentation
  164. for details). Note that this includes both user space functions (entries
  165. containing a ``[.]``) and kernel functions accounted to the process (entries
  166. containing a ``[k]``). perf has command-line modifiers that can be used to
  167. restrict the profiling to kernel or user space, among others.
  168. Notice also that the above report shows an entry for ``busybox``, which is
  169. the executable that implements ``wget`` in Yocto, but that instead of a
  170. useful function name in that entry, it displays a not-so-friendly hex
  171. value instead. The steps below will show how to fix that problem.
  172. Before we do that, however, let's try running a different profile, one
  173. which shows something a little more interesting. The only difference
  174. between the new profile and the previous one is that we'll add the ``-g``
  175. option, which will record not just the address of a sampled function,
  176. but the entire call chain to the sampled function as well::
  177. root@crownbay:~# perf record -g wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2
  178. Connecting to downloads.yoctoproject.org (140.211.169.59:80)
  179. linux-2.6.19.2.tar.b 100% |************************************************| 41727k 0:00:00 ETA
  180. [ perf record: Woken up 3 times to write data ]
  181. [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]
  182. root@crownbay:~# perf report
  183. .. image:: figures/perf-wget-g-copy-to-user-expanded-stripped.png
  184. :align: center
  185. :width: 70%
  186. Using the call graph view, we can actually see not only which functions
  187. took the most time, but we can also see a summary of how those functions
  188. were called and learn something about how the program interacts with the
  189. kernel in the process.
  190. Notice that each entry in the above screenshot now contains a ``+`` on the
  191. left side. This means that we can expand the entry and drill down
  192. into the call chains that feed into that entry. Pressing ``Enter`` on any
  193. one of them will expand the call chain (you can also press ``E`` to expand
  194. them all at the same time or ``C`` to collapse them all).
  195. In the screenshot above, we've toggled the ``__copy_to_user_ll()`` entry
  196. and several subnodes all the way down. This lets us see which call chains
  197. contributed to the profiled ``__copy_to_user_ll()`` function which
  198. contributed 1.77% to the total profile.
  199. As a bit of background explanation for these call chains, think about
  200. what happens at a high level when you run ``wget`` to get a file out on the
  201. network. Basically what happens is that the data comes into the kernel
  202. via the network connection (socket) and is passed to the user space
  203. program ``wget`` (which is actually a part of BusyBox, but that's not
  204. important for now), which takes the buffers the kernel passes to it and
  205. writes it to a disk file to save it.
  206. The part of this process that we're looking at in the above call stacks
  207. is the part where the kernel passes the data it has read from the socket
  208. down to wget i.e. a ``copy-to-user``.
  209. Notice also that here there's also a case where the hex value is
  210. displayed in the call stack, here in the expanded ``sys_clock_gettime()``
  211. function. Later we'll see it resolve to a user space function call in
  212. BusyBox.
  213. .. image:: figures/perf-wget-g-copy-from-user-expanded-stripped.png
  214. :align: center
  215. :width: 70%
  216. The above screenshot shows the other half of the journey for the data ---
  217. from the ``wget`` program's user space buffers to disk. To get the buffers to
  218. disk, the wget program issues a ``write(2)``, which does a ``copy-from-user`` to
  219. the kernel, which then takes care via some circuitous path (probably
  220. also present somewhere in the profile data), to get it safely to disk.
  221. Now that we've seen the basic layout of the profile data and the basics
  222. of how to extract useful information out of it, let's get back to the
  223. task at hand and see if we can get some basic idea about where the time
  224. is spent in the program we're profiling, wget. Remember that wget is
  225. actually implemented as an applet in BusyBox, so while the process name
  226. is ``wget``, the executable we're actually interested in is ``busybox``.
  227. Therefore, let's expand the first entry containing BusyBox:
  228. .. image:: figures/perf-wget-busybox-expanded-stripped.png
  229. :align: center
  230. :width: 70%
  231. Again, before we expanded we saw that the function was labeled with a
  232. hex value instead of a symbol as with most of the kernel entries.
  233. Expanding the BusyBox entry doesn't make it any better.
  234. The problem is that perf can't find the symbol information for the
  235. ``busybox`` binary, which is actually stripped out by the Yocto build
  236. system.
  237. One way around that is to put the following in your ``local.conf`` file
  238. when you build the image::
  239. INHIBIT_PACKAGE_STRIP = "1"
  240. However, we already have an image with the binaries stripped, so
  241. what can we do to get perf to resolve the symbols? Basically we need to
  242. install the debugging information for the BusyBox package.
  243. To generate the debug info for the packages in the image, we can add
  244. ``dbg-pkgs`` to :term:`EXTRA_IMAGE_FEATURES` in ``local.conf``. For example::
  245. EXTRA_IMAGE_FEATURES = "debug-tweaks tools-profile dbg-pkgs"
  246. Additionally, in order to generate the type of debugging information that perf
  247. understands, we also need to set :term:`PACKAGE_DEBUG_SPLIT_STYLE`
  248. in the ``local.conf`` file::
  249. PACKAGE_DEBUG_SPLIT_STYLE = 'debug-file-directory'
  250. Once we've done that, we can install the debugging information for BusyBox. The
  251. debug packages once built can be found in ``build/tmp/deploy/rpm/*``
  252. on the host system. Find the ``busybox-dbg-...rpm`` file and copy it
  253. to the target. For example::
  254. [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2_32/busybox-dbg-1.20.2-r2.core2_32.rpm root@192.168.1.31:
  255. busybox-dbg-1.20.2-r2.core2_32.rpm 100% 1826KB 1.8MB/s 00:01
  256. Now install the debug RPM on the target::
  257. root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2_32.rpm
  258. Now that the debugging information is installed, we see that the BusyBox entries now display
  259. their functions symbolically:
  260. .. image:: figures/perf-wget-busybox-debuginfo.png
  261. :align: center
  262. :width: 70%
  263. If we expand one of the entries and press ``Enter`` on a leaf node, we're
  264. presented with a menu of actions we can take to get more information
  265. related to that entry:
  266. .. image:: figures/perf-wget-busybox-dso-zoom-menu.png
  267. :align: center
  268. :width: 70%
  269. One of these actions allows us to show a view that displays a
  270. busybox-centric view of the profiled functions (in this case we've also
  271. expanded all the nodes using the ``E`` key):
  272. .. image:: figures/perf-wget-busybox-dso-zoom.png
  273. :align: center
  274. :width: 70%
  275. Finally, we can see that now that the BusyBox debugging information is installed,
  276. the previously unresolved symbol in the ``sys_clock_gettime()`` entry
  277. mentioned previously is now resolved, and shows that the
  278. ``sys_clock_gettime`` system call that was the source of 6.75% of the
  279. ``copy-to-user`` overhead was initiated by the ``handle_input()`` BusyBox
  280. function:
  281. .. image:: figures/perf-wget-g-copy-to-user-expanded-debuginfo.png
  282. :align: center
  283. :width: 70%
  284. At the lowest level of detail, we can dive down to the assembly level
  285. and see which instructions caused the most overhead in a function.
  286. Pressing ``Enter`` on the ``udhcpc_main`` function, we're again presented
  287. with a menu:
  288. .. image:: figures/perf-wget-busybox-annotate-menu.png
  289. :align: center
  290. :width: 70%
  291. Selecting ``Annotate udhcpc_main``, we get a detailed listing of
  292. percentages by instruction for the ``udhcpc_main`` function. From the
  293. display, we can see that over 50% of the time spent in this function is
  294. taken up by a couple tests and the move of a constant (1) to a register:
  295. .. image:: figures/perf-wget-busybox-annotate-udhcpc.png
  296. :align: center
  297. :width: 70%
  298. As a segue into tracing, let's try another profile using a different
  299. counter, something other than the default ``cycles``.
  300. The tracing and profiling infrastructure in Linux has become unified in
  301. a way that allows us to use the same tool with a completely different
  302. set of counters, not just the standard hardware counters that
  303. traditional tools have had to restrict themselves to (the
  304. traditional tools can now actually make use of the expanded possibilities now
  305. available to them, and in some cases have, as mentioned previously).
  306. We can get a list of the available events that can be used to profile a
  307. workload via ``perf list``::
  308. root@crownbay:~# perf list
  309. List of pre-defined events (to be used in -e):
  310. cpu-cycles OR cycles [Hardware event]
  311. stalled-cycles-frontend OR idle-cycles-frontend [Hardware event]
  312. stalled-cycles-backend OR idle-cycles-backend [Hardware event]
  313. instructions [Hardware event]
  314. cache-references [Hardware event]
  315. cache-misses [Hardware event]
  316. branch-instructions OR branches [Hardware event]
  317. branch-misses [Hardware event]
  318. bus-cycles [Hardware event]
  319. ref-cycles [Hardware event]
  320. cpu-clock [Software event]
  321. task-clock [Software event]
  322. page-faults OR faults [Software event]
  323. minor-faults [Software event]
  324. major-faults [Software event]
  325. context-switches OR cs [Software event]
  326. cpu-migrations OR migrations [Software event]
  327. alignment-faults [Software event]
  328. emulation-faults [Software event]
  329. L1-dcache-loads [Hardware cache event]
  330. L1-dcache-load-misses [Hardware cache event]
  331. L1-dcache-prefetch-misses [Hardware cache event]
  332. L1-icache-loads [Hardware cache event]
  333. L1-icache-load-misses [Hardware cache event]
  334. .
  335. .
  336. .
  337. rNNN [Raw hardware event descriptor]
  338. cpu/t1=v1[,t2=v2,t3 ...]/modifier [Raw hardware event descriptor]
  339. (see 'perf list --help' on how to encode it)
  340. mem:<addr>[:access] [Hardware breakpoint]
  341. sunrpc:rpc_call_status [Tracepoint event]
  342. sunrpc:rpc_bind_status [Tracepoint event]
  343. sunrpc:rpc_connect_status [Tracepoint event]
  344. sunrpc:rpc_task_begin [Tracepoint event]
  345. skb:kfree_skb [Tracepoint event]
  346. skb:consume_skb [Tracepoint event]
  347. skb:skb_copy_datagram_iovec [Tracepoint event]
  348. net:net_dev_xmit [Tracepoint event]
  349. net:net_dev_queue [Tracepoint event]
  350. net:netif_receive_skb [Tracepoint event]
  351. net:netif_rx [Tracepoint event]
  352. napi:napi_poll [Tracepoint event]
  353. sock:sock_rcvqueue_full [Tracepoint event]
  354. sock:sock_exceed_buf_limit [Tracepoint event]
  355. udp:udp_fail_queue_rcv_skb [Tracepoint event]
  356. hda:hda_send_cmd [Tracepoint event]
  357. hda:hda_get_response [Tracepoint event]
  358. hda:hda_bus_reset [Tracepoint event]
  359. scsi:scsi_dispatch_cmd_start [Tracepoint event]
  360. scsi:scsi_dispatch_cmd_error [Tracepoint event]
  361. scsi:scsi_eh_wakeup [Tracepoint event]
  362. drm:drm_vblank_event [Tracepoint event]
  363. drm:drm_vblank_event_queued [Tracepoint event]
  364. drm:drm_vblank_event_delivered [Tracepoint event]
  365. random:mix_pool_bytes [Tracepoint event]
  366. random:mix_pool_bytes_nolock [Tracepoint event]
  367. random:credit_entropy_bits [Tracepoint event]
  368. gpio:gpio_direction [Tracepoint event]
  369. gpio:gpio_value [Tracepoint event]
  370. block:block_rq_abort [Tracepoint event]
  371. block:block_rq_requeue [Tracepoint event]
  372. block:block_rq_issue [Tracepoint event]
  373. block:block_bio_bounce [Tracepoint event]
  374. block:block_bio_complete [Tracepoint event]
  375. block:block_bio_backmerge [Tracepoint event]
  376. .
  377. .
  378. writeback:writeback_wake_thread [Tracepoint event]
  379. writeback:writeback_wake_forker_thread [Tracepoint event]
  380. writeback:writeback_bdi_register [Tracepoint event]
  381. .
  382. .
  383. writeback:writeback_single_inode_requeue [Tracepoint event]
  384. writeback:writeback_single_inode [Tracepoint event]
  385. kmem:kmalloc [Tracepoint event]
  386. kmem:kmem_cache_alloc [Tracepoint event]
  387. kmem:mm_page_alloc [Tracepoint event]
  388. kmem:mm_page_alloc_zone_locked [Tracepoint event]
  389. kmem:mm_page_pcpu_drain [Tracepoint event]
  390. kmem:mm_page_alloc_extfrag [Tracepoint event]
  391. vmscan:mm_vmscan_kswapd_sleep [Tracepoint event]
  392. vmscan:mm_vmscan_kswapd_wake [Tracepoint event]
  393. vmscan:mm_vmscan_wakeup_kswapd [Tracepoint event]
  394. vmscan:mm_vmscan_direct_reclaim_begin [Tracepoint event]
  395. .
  396. .
  397. module:module_get [Tracepoint event]
  398. module:module_put [Tracepoint event]
  399. module:module_request [Tracepoint event]
  400. sched:sched_kthread_stop [Tracepoint event]
  401. sched:sched_wakeup [Tracepoint event]
  402. sched:sched_wakeup_new [Tracepoint event]
  403. sched:sched_process_fork [Tracepoint event]
  404. sched:sched_process_exec [Tracepoint event]
  405. sched:sched_stat_runtime [Tracepoint event]
  406. rcu:rcu_utilization [Tracepoint event]
  407. workqueue:workqueue_queue_work [Tracepoint event]
  408. workqueue:workqueue_execute_end [Tracepoint event]
  409. signal:signal_generate [Tracepoint event]
  410. signal:signal_deliver [Tracepoint event]
  411. timer:timer_init [Tracepoint event]
  412. timer:timer_start [Tracepoint event]
  413. timer:hrtimer_cancel [Tracepoint event]
  414. timer:itimer_state [Tracepoint event]
  415. timer:itimer_expire [Tracepoint event]
  416. irq:irq_handler_entry [Tracepoint event]
  417. irq:irq_handler_exit [Tracepoint event]
  418. irq:softirq_entry [Tracepoint event]
  419. irq:softirq_exit [Tracepoint event]
  420. irq:softirq_raise [Tracepoint event]
  421. printk:console [Tracepoint event]
  422. task:task_newtask [Tracepoint event]
  423. task:task_rename [Tracepoint event]
  424. syscalls:sys_enter_socketcall [Tracepoint event]
  425. syscalls:sys_exit_socketcall [Tracepoint event]
  426. .
  427. .
  428. .
  429. syscalls:sys_enter_unshare [Tracepoint event]
  430. syscalls:sys_exit_unshare [Tracepoint event]
  431. raw_syscalls:sys_enter [Tracepoint event]
  432. raw_syscalls:sys_exit [Tracepoint event]
  433. .. admonition:: Tying it Together
  434. These are exactly the same set of events defined by the trace event
  435. subsystem and exposed by ftrace / trace-cmd / KernelShark as files in
  436. ``/sys/kernel/debug/tracing/events``, by SystemTap as
  437. kernel.trace("tracepoint_name") and (partially) accessed by LTTng.
  438. Only a subset of these would be of interest to us when looking at this
  439. workload, so let's choose the most likely subsystems (identified by the
  440. string before the colon in the ``Tracepoint`` events) and do a ``perf stat``
  441. run using only those subsystem wildcards::
  442. root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2
  443. Performance counter stats for 'wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2':
  444. 23323 skb:kfree_skb
  445. 0 skb:consume_skb
  446. 49897 skb:skb_copy_datagram_iovec
  447. 6217 net:net_dev_xmit
  448. 6217 net:net_dev_queue
  449. 7962 net:netif_receive_skb
  450. 2 net:netif_rx
  451. 8340 napi:napi_poll
  452. 0 sched:sched_kthread_stop
  453. 0 sched:sched_kthread_stop_ret
  454. 3749 sched:sched_wakeup
  455. 0 sched:sched_wakeup_new
  456. 0 sched:sched_switch
  457. 29 sched:sched_migrate_task
  458. 0 sched:sched_process_free
  459. 1 sched:sched_process_exit
  460. 0 sched:sched_wait_task
  461. 0 sched:sched_process_wait
  462. 0 sched:sched_process_fork
  463. 1 sched:sched_process_exec
  464. 0 sched:sched_stat_wait
  465. 2106519415641 sched:sched_stat_sleep
  466. 0 sched:sched_stat_iowait
  467. 147453613 sched:sched_stat_blocked
  468. 12903026955 sched:sched_stat_runtime
  469. 0 sched:sched_pi_setprio
  470. 3574 workqueue:workqueue_queue_work
  471. 3574 workqueue:workqueue_activate_work
  472. 0 workqueue:workqueue_execute_start
  473. 0 workqueue:workqueue_execute_end
  474. 16631 irq:irq_handler_entry
  475. 16631 irq:irq_handler_exit
  476. 28521 irq:softirq_entry
  477. 28521 irq:softirq_exit
  478. 28728 irq:softirq_raise
  479. 1 syscalls:sys_enter_sendmmsg
  480. 1 syscalls:sys_exit_sendmmsg
  481. 0 syscalls:sys_enter_recvmmsg
  482. 0 syscalls:sys_exit_recvmmsg
  483. 14 syscalls:sys_enter_socketcall
  484. 14 syscalls:sys_exit_socketcall
  485. .
  486. .
  487. .
  488. 16965 syscalls:sys_enter_read
  489. 16965 syscalls:sys_exit_read
  490. 12854 syscalls:sys_enter_write
  491. 12854 syscalls:sys_exit_write
  492. .
  493. .
  494. .
  495. 58.029710972 seconds time elapsed
  496. Let's pick one of these tracepoints
  497. and tell perf to do a profile using it as the sampling event::
  498. root@crownbay:~# perf record -g -e sched:sched_wakeup wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2
  499. .. image:: figures/sched-wakeup-profile.png
  500. :align: center
  501. :width: 70%
  502. The screenshot above shows the results of running a profile using
  503. sched:sched_switch tracepoint, which shows the relative costs of various
  504. paths to ``sched_wakeup`` (note that ``sched_wakeup`` is the name of the
  505. tracepoint --- it's actually defined just inside ``ttwu_do_wakeup()``, which
  506. accounts for the function name actually displayed in the profile:
  507. .. code-block:: c
  508. /*
  509. * Mark the task runnable and perform wakeup-preemption.
  510. */
  511. static void
  512. ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)
  513. {
  514. trace_sched_wakeup(p, true);
  515. .
  516. .
  517. .
  518. }
  519. A couple of the more interesting
  520. call chains are expanded and displayed above, basically some network
  521. receive paths that presumably end up waking up wget (BusyBox) when
  522. network data is ready.
  523. Note that because tracepoints are normally used for tracing, the default
  524. sampling period for tracepoints is ``1`` i.e. for tracepoints perf will
  525. sample on every event occurrence (this can be changed using the ``-c``
  526. option). This is in contrast to hardware counters such as for example
  527. the default ``cycles`` hardware counter used for normal profiling, where
  528. sampling periods are much higher (in the thousands) because profiling
  529. should have as low an overhead as possible and sampling on every cycle
  530. would be prohibitively expensive.
  531. Using perf to do Basic Tracing
  532. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  533. Profiling is a great tool for solving many problems or for getting a
  534. high-level view of what's going on with a workload or across the system.
  535. It is however by definition an approximation, as suggested by the most
  536. prominent word associated with it, ``sampling``. On the one hand, it
  537. allows a representative picture of what's going on in the system to be
  538. cheaply taken, but alternatively, that cheapness limits its utility
  539. when that data suggests a need to "dive down" more deeply to discover
  540. what's really going on. In such cases, the only way to see what's really
  541. going on is to be able to look at (or summarize more intelligently) the
  542. individual steps that go into the higher-level behavior exposed by the
  543. coarse-grained profiling data.
  544. As a concrete example, we can trace all the events we think might be
  545. applicable to our workload::
  546. root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*
  547. -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write
  548. wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2
  549. We can look at the raw trace output using ``perf script`` with no
  550. arguments::
  551. root@crownbay:~# perf script
  552. perf 1262 [000] 11624.857082: sys_exit_read: 0x0
  553. perf 1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000
  554. wget 1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]
  555. wget 1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]
  556. wget 1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]
  557. wget 1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200
  558. wget 1262 [001] 11624.858177: sys_exit_read: 0x200
  559. wget 1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308
  560. wget 1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308
  561. wget 1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]
  562. wget 1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]
  563. wget 1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]
  564. wget 1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400
  565. wget 1262 [001] 11624.859192: sys_exit_read: 0x1d7
  566. wget 1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400
  567. wget 1262 [001] 11624.859233: sys_exit_read: 0x0
  568. wget 1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200
  569. wget 1262 [001] 11624.859584: sys_exit_read: 0x200
  570. wget 1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400
  571. wget 1262 [001] 11624.859888: sys_exit_read: 0x400
  572. wget 1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400
  573. wget 1262 [001] 11624.859944: sys_exit_read: 0x400
  574. This gives us a detailed timestamped sequence of events that occurred within the
  575. workload with respect to those events.
  576. In many ways, profiling can be viewed as a subset of tracing ---
  577. theoretically, if you have a set of trace events that's sufficient to
  578. capture all the important aspects of a workload, you can derive any of
  579. the results or views that a profiling run can.
  580. Another aspect of traditional profiling is that while powerful in many
  581. ways, it's limited by the granularity of the underlying data. Profiling
  582. tools offer various ways of sorting and presenting the sample data,
  583. which make it much more useful and amenable to user experimentation, but
  584. in the end it can't be used in an open-ended way to extract data that
  585. just isn't present as a consequence of the fact that conceptually, most
  586. of it has been thrown away.
  587. Full-blown detailed tracing data does however offer the opportunity to
  588. manipulate and present the information collected during a tracing run in
  589. an infinite variety of ways.
  590. Another way to look at it is that there are only so many ways that the
  591. 'primitive' counters can be used on their own to generate interesting
  592. output; to get anything more complicated than simple counts requires
  593. some amount of additional logic, which is typically specific to the
  594. problem at hand. For example, if we wanted to make use of a 'counter'
  595. that maps to the value of the time difference between when a process was
  596. scheduled to run on a processor and the time it actually ran, we
  597. wouldn't expect such a counter to exist on its own, but we could derive
  598. one called say ``wakeup_latency`` and use it to extract a useful view of
  599. that metric from trace data. Likewise, we really can't figure out from
  600. standard profiling tools how much data every process on the system reads
  601. and writes, along with how many of those reads and writes fail
  602. completely. If we have sufficient trace data, however, we could with the
  603. right tools easily extract and present that information, but we'd need
  604. something other than ready-made profiling tools to do that.
  605. Luckily, there is a general-purpose way to handle such needs, called
  606. "programming languages". Making programming languages easily available
  607. to apply to such problems given the specific format of data is called a
  608. 'programming language binding' for that data and language. perf supports
  609. two programming language bindings, one for Python and one for Perl.
  610. .. admonition:: Tying it Together
  611. Language bindings for manipulating and aggregating trace data are of
  612. course not a new idea. One of the first projects to do this was IBM's
  613. DProbes dpcc compiler, an ANSI C compiler which targeted a low-level
  614. assembly language running on an in-kernel interpreter on the target
  615. system. This is exactly analogous to what Sun's DTrace did, except
  616. that DTrace invented its own language for the purpose. SystemTap,
  617. heavily inspired by DTrace, also created its own one-off language,
  618. but rather than running the product on an in-kernel interpreter,
  619. created an elaborate compiler-based machinery to translate its
  620. language into kernel modules written in C.
  621. Now that we have the trace data in ``perf.data``, we can use ``perf script
  622. -g`` to generate a skeleton script with handlers for the read / write
  623. entry / exit events we recorded::
  624. root@crownbay:~# perf script -g python
  625. generated Python script: perf-script.py
  626. The skeleton script just creates a Python function for each event type in the
  627. ``perf.data`` file. The body of each function just prints the event name along
  628. with its parameters. For example:
  629. .. code-block:: python
  630. def net__netif_rx(event_name, context, common_cpu,
  631. common_secs, common_nsecs, common_pid, common_comm,
  632. skbaddr, len, name):
  633. print_header(event_name, common_cpu, common_secs, common_nsecs,
  634. common_pid, common_comm)
  635. print "skbaddr=%u, len=%u, name=%s\n" % (skbaddr, len, name),
  636. We can run that script directly to print all of the events contained in the
  637. ``perf.data`` file::
  638. root@crownbay:~# perf script -s perf-script.py
  639. in trace_begin
  640. syscalls__sys_exit_read 0 11624.857082795 1262 perf nr=3, ret=0
  641. sched__sched_wakeup 0 11624.857193498 1262 perf comm=migration/0, pid=6, prio=0, success=1, target_cpu=0
  642. irq__softirq_raise 1 11624.858021635 1262 wget vec=TIMER
  643. irq__softirq_entry 1 11624.858074075 1262 wget vec=TIMER
  644. irq__softirq_exit 1 11624.858081389 1262 wget vec=TIMER
  645. syscalls__sys_enter_read 1 11624.858166434 1262 wget nr=3, fd=3, buf=3213019456, count=512
  646. syscalls__sys_exit_read 1 11624.858177924 1262 wget nr=3, ret=512
  647. skb__kfree_skb 1 11624.858878188 1262 wget skbaddr=3945041280, location=3243922184, protocol=0
  648. skb__kfree_skb 1 11624.858945608 1262 wget skbaddr=3945037824, location=3243922184, protocol=0
  649. irq__softirq_raise 1 11624.859020942 1262 wget vec=TIMER
  650. irq__softirq_entry 1 11624.859076935 1262 wget vec=TIMER
  651. irq__softirq_exit 1 11624.859083469 1262 wget vec=TIMER
  652. syscalls__sys_enter_read 1 11624.859167565 1262 wget nr=3, fd=3, buf=3077701632, count=1024
  653. syscalls__sys_exit_read 1 11624.859192533 1262 wget nr=3, ret=471
  654. syscalls__sys_enter_read 1 11624.859228072 1262 wget nr=3, fd=3, buf=3077701632, count=1024
  655. syscalls__sys_exit_read 1 11624.859233707 1262 wget nr=3, ret=0
  656. syscalls__sys_enter_read 1 11624.859573008 1262 wget nr=3, fd=3, buf=3213018496, count=512
  657. syscalls__sys_exit_read 1 11624.859584818 1262 wget nr=3, ret=512
  658. syscalls__sys_enter_read 1 11624.859864562 1262 wget nr=3, fd=3, buf=3077701632, count=1024
  659. syscalls__sys_exit_read 1 11624.859888770 1262 wget nr=3, ret=1024
  660. syscalls__sys_enter_read 1 11624.859935140 1262 wget nr=3, fd=3, buf=3077701632, count=1024
  661. syscalls__sys_exit_read 1 11624.859944032 1262 wget nr=3, ret=1024
  662. That in itself isn't very useful; after all, we can accomplish pretty much the
  663. same thing by just running ``perf script`` without arguments in the same
  664. directory as the ``perf.data`` file.
  665. We can however replace the print statements in the generated function
  666. bodies with whatever we want, and thereby make it infinitely more
  667. useful.
  668. As a simple example, let's just replace the print statements in the
  669. function bodies with a simple function that does nothing but increment a
  670. per-event count. When the program is run against a perf.data file, each
  671. time a particular event is encountered, a tally is incremented for that
  672. event. For example:
  673. .. code-block:: python
  674. def net__netif_rx(event_name, context, common_cpu,
  675. common_secs, common_nsecs, common_pid, common_comm,
  676. skbaddr, len, name):
  677. inc_counts(event_name)
  678. Each event handler function in the generated code
  679. is modified to do this. For convenience, we define a common function
  680. called ``inc_counts()`` that each handler calls; ``inc_counts()`` just tallies
  681. a count for each event using the ``counts`` hash, which is a specialized
  682. hash function that does Perl-like autovivification, a capability that's
  683. extremely useful for kinds of multi-level aggregation commonly used in
  684. processing traces (see perf's documentation on the Python language
  685. binding for details):
  686. .. code-block:: python
  687. counts = autodict()
  688. def inc_counts(event_name):
  689. try:
  690. counts[event_name] += 1
  691. except TypeError:
  692. counts[event_name] = 1
  693. Finally, at the end of the trace processing run, we want to print the
  694. result of all the per-event tallies. For that, we use the special
  695. ``trace_end()`` function:
  696. .. code-block:: python
  697. def trace_end():
  698. for event_name, count in counts.iteritems():
  699. print "%-40s %10s\n" % (event_name, count)
  700. The end result is a summary of all the events recorded in the trace::
  701. skb__skb_copy_datagram_iovec 13148
  702. irq__softirq_entry 4796
  703. irq__irq_handler_exit 3805
  704. irq__softirq_exit 4795
  705. syscalls__sys_enter_write 8990
  706. net__net_dev_xmit 652
  707. skb__kfree_skb 4047
  708. sched__sched_wakeup 1155
  709. irq__irq_handler_entry 3804
  710. irq__softirq_raise 4799
  711. net__net_dev_queue 652
  712. syscalls__sys_enter_read 17599
  713. net__netif_receive_skb 1743
  714. syscalls__sys_exit_read 17598
  715. net__netif_rx 2
  716. napi__napi_poll 1877
  717. syscalls__sys_exit_write 8990
  718. Note that this is
  719. pretty much exactly the same information we get from ``perf stat``, which
  720. goes a little way to support the idea mentioned previously that given
  721. the right kind of trace data, higher-level profiling-type summaries can
  722. be derived from it.
  723. Documentation on using the `'perf script' Python
  724. binding <https://linux.die.net/man/1/perf-script-python>`__.
  725. System-Wide Tracing and Profiling
  726. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  727. The examples so far have focused on tracing a particular program or
  728. workload --- that is, every profiling run has specified the program
  729. to profile in the command-line e.g. ``perf record wget ...``.
  730. It's also possible, and more interesting in many cases, to run a
  731. system-wide profile or trace while running the workload in a separate
  732. shell.
  733. To do system-wide profiling or tracing, you typically use the ``-a`` flag to
  734. ``perf record``.
  735. To demonstrate this, open up one window and start the profile using the
  736. ``-a`` flag (press ``Ctrl-C`` to stop tracing)::
  737. root@crownbay:~# perf record -g -a
  738. ^C[ perf record: Woken up 6 times to write data ]
  739. [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]
  740. In another window, run the ``wget`` test::
  741. root@crownbay:~# wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2
  742. Connecting to downloads.yoctoproject.org (140.211.169.59:80)
  743. linux-2.6.19.2.tar.b 100% \|*******************************\| 41727k 0:00:00 ETA
  744. Here we see entries not only for our ``wget`` load, but for
  745. other processes running on the system as well:
  746. .. image:: figures/perf-systemwide.png
  747. :align: center
  748. :width: 70%
  749. In the snapshot above, we can see call chains that originate in ``libc``, and
  750. a call chain from ``Xorg`` that demonstrates that we're using a proprietary X
  751. driver in user space (notice the presence of ``PVR`` and some other
  752. unresolvable symbols in the expanded ``Xorg`` call chain).
  753. Note also that we have both kernel and user space entries in the above
  754. snapshot. We can also tell perf to focus on user space but providing a
  755. modifier, in this case ``u``, to the ``cycles`` hardware counter when we
  756. record a profile::
  757. root@crownbay:~# perf record -g -a -e cycles:u
  758. ^C[ perf record: Woken up 2 times to write data ]
  759. [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]
  760. .. image:: figures/perf-report-cycles-u.png
  761. :align: center
  762. :width: 70%
  763. Notice in the screenshot above, we see only user space entries (``[.]``)
  764. Finally, we can press ``Enter`` on a leaf node and select the ``Zoom into
  765. DSO`` menu item to show only entries associated with a specific DSO. In
  766. the screenshot below, we've zoomed into the ``libc`` DSO which shows all
  767. the entries associated with the ``libc-xxx.so`` DSO.
  768. .. image:: figures/perf-systemwide-libc.png
  769. :align: center
  770. :width: 70%
  771. We can also use the system-wide ``-a`` switch to do system-wide tracing.
  772. Here we'll trace a couple of scheduler events::
  773. root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup
  774. ^C[ perf record: Woken up 38 times to write data ]
  775. [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]
  776. We can look at the raw output using ``perf script`` with no arguments::
  777. root@crownbay:~# perf script
  778. perf 1383 [001] 6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001
  779. perf 1383 [001] 6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==> next_comm=kworker/1:1 next_pid=21 next_prio=120
  780. kworker/1:1 21 [001] 6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==> next_comm=perf next_pid=1383 next_prio=120
  781. swapper 0 [000] 6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000
  782. swapper 0 [000] 6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/0:3 next_pid=1209 next_prio=120
  783. kworker/0:3 1209 [000] 6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==> next_comm=swapper/0 next_pid=0 next_prio=120
  784. perf 1383 [001] 6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001
  785. perf 1383 [001] 6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==> next_comm=kworker/1:1 next_pid=21 next_prio=120
  786. kworker/1:1 21 [001] 6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==> next_comm=perf next_pid=1383 next_prio=120
  787. perf 1383 [001] 6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001
  788. Filtering
  789. ^^^^^^^^^
  790. Notice that there are many events that don't really have anything to
  791. do with what we're interested in, namely events that schedule ``perf``
  792. itself in and out or that wake perf up. We can get rid of those by using
  793. the ``--filter`` option --- for each event we specify using ``-e``, we can add a
  794. ``--filter`` after that to filter out trace events that contain fields with
  795. specific values::
  796. root@crownbay:~# perf record -a -e sched:sched_switch --filter 'next_comm != perf && prev_comm != perf' -e sched:sched_wakeup --filter 'comm != perf'
  797. ^C[ perf record: Woken up 38 times to write data ]
  798. [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]
  799. root@crownbay:~# perf script
  800. swapper 0 [000] 7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/0:3 next_pid=1209 next_prio=120
  801. kworker/0:3 1209 [000] 7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==> next_comm=swapper/0 next_pid=0 next_prio=120
  802. perf 1407 [001] 7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001
  803. perf 1407 [001] 7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001
  804. perf 1407 [001] 7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001
  805. perf 1407 [001] 7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001
  806. perf 1407 [001] 7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001
  807. perf 1407 [001] 7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001
  808. swapper 0 [001] 7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001
  809. swapper 0 [001] 7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/1:1 next_pid=21 next_prio=120
  810. kworker/1:1 21 [001] 7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==> next_comm=swapper/1 next_pid=0 next_prio=120
  811. swapper 0 [000] 7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000
  812. swapper 0 [000] 7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/0:3 next_pid=1209 next_prio=120
  813. kworker/0:3 1209 [000] 7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==> next_comm=swapper/0 next_pid=0 next_prio=120
  814. In this case, we've filtered out all events that have
  815. ``perf`` in their ``comm``, ``comm_prev`` or ``comm_next`` fields. Notice that
  816. there are still events recorded for perf, but notice that those events
  817. don't have values of ``perf`` for the filtered fields. To completely
  818. filter out anything from perf will require a bit more work, but for the
  819. purpose of demonstrating how to use filters, it's close enough.
  820. .. admonition:: Tying it Together
  821. These are exactly the same set of event filters defined by the trace
  822. event subsystem. See the ftrace / trace-cmd / KernelShark section for more
  823. discussion about these event filters.
  824. .. admonition:: Tying it Together
  825. These event filters are implemented by a special-purpose
  826. pseudo-interpreter in the kernel and are an integral and
  827. indispensable part of the perf design as it relates to tracing.
  828. kernel-based event filters provide a mechanism to precisely throttle
  829. the event stream that appears in user space, where it makes sense to
  830. provide bindings to real programming languages for post-processing the
  831. event stream. This architecture allows for the intelligent and
  832. flexible partitioning of processing between the kernel and user
  833. space. Contrast this with other tools such as SystemTap, which does
  834. all of its processing in the kernel and as such requires a special
  835. project-defined language in order to accommodate that design, or
  836. LTTng, where everything is sent to user space and as such requires a
  837. super-efficient kernel-to-user space transport mechanism in order to
  838. function properly. While perf certainly can benefit from for instance
  839. advances in the design of the transport, it doesn't fundamentally
  840. depend on them. Basically, if you find that your perf tracing
  841. application is causing buffer I/O overruns, it probably means that
  842. you aren't taking enough advantage of the kernel filtering engine.
  843. Using Dynamic Tracepoints
  844. ~~~~~~~~~~~~~~~~~~~~~~~~~
  845. perf isn't restricted to the fixed set of static tracepoints listed by
  846. ``perf list``. Users can also add their own "dynamic" tracepoints anywhere
  847. in the kernel. For example, suppose we want to define our own
  848. tracepoint on ``do_fork()``. We can do that using the ``perf probe`` perf
  849. subcommand::
  850. root@crownbay:~# perf probe do_fork
  851. Added new event:
  852. probe:do_fork (on do_fork)
  853. You can now use it in all perf tools, such as:
  854. perf record -e probe:do_fork -aR sleep 1
  855. Adding a new tracepoint via
  856. ``perf probe`` results in an event with all the expected files and format
  857. in ``/sys/kernel/debug/tracing/events``, just the same as for static
  858. tracepoints (as discussed in more detail in the trace events subsystem
  859. section::
  860. root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al
  861. drwxr-xr-x 2 root root 0 Oct 28 11:42 .
  862. drwxr-xr-x 3 root root 0 Oct 28 11:42 ..
  863. -rw-r--r-- 1 root root 0 Oct 28 11:42 enable
  864. -rw-r--r-- 1 root root 0 Oct 28 11:42 filter
  865. -r--r--r-- 1 root root 0 Oct 28 11:42 format
  866. -r--r--r-- 1 root root 0 Oct 28 11:42 id
  867. root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format
  868. name: do_fork
  869. ID: 944
  870. format:
  871. field:unsigned short common_type; offset:0; size:2; signed:0;
  872. field:unsigned char common_flags; offset:2; size:1; signed:0;
  873. field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
  874. field:int common_pid; offset:4; size:4; signed:1;
  875. field:int common_padding; offset:8; size:4; signed:1;
  876. field:unsigned long __probe_ip; offset:12; size:4; signed:0;
  877. print fmt: "(%lx)", REC->__probe_ip
  878. We can list all dynamic tracepoints currently in
  879. existence::
  880. root@crownbay:~# perf probe -l
  881. probe:do_fork (on do_fork)
  882. probe:schedule (on schedule)
  883. Let's record system-wide (``sleep 30`` is a
  884. trick for recording system-wide but basically do nothing and then wake
  885. up after 30 seconds)::
  886. root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30
  887. [ perf record: Woken up 1 times to write data ]
  888. [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]
  889. Using ``perf script`` we can see each ``do_fork`` event that fired::
  890. root@crownbay:~# perf script
  891. # ========
  892. # captured on: Sun Oct 28 11:55:18 2012
  893. # hostname : crownbay
  894. # os release : 3.4.11-yocto-standard
  895. # perf version : 3.4.11
  896. # arch : i686
  897. # nrcpus online : 2
  898. # nrcpus avail : 2
  899. # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz
  900. # cpuid : GenuineIntel,6,38,1
  901. # total memory : 1017184 kB
  902. # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30
  903. # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern
  904. = 0, id = { 5, 6 }
  905. # HEADER_CPU_TOPOLOGY info available, use -I to display
  906. # ========
  907. #
  908. matchbox-deskto 1197 [001] 34211.378318: do_fork: (c1028460)
  909. matchbox-deskto 1295 [001] 34211.380388: do_fork: (c1028460)
  910. pcmanfm 1296 [000] 34211.632350: do_fork: (c1028460)
  911. pcmanfm 1296 [000] 34211.639917: do_fork: (c1028460)
  912. matchbox-deskto 1197 [001] 34217.541603: do_fork: (c1028460)
  913. matchbox-deskto 1299 [001] 34217.543584: do_fork: (c1028460)
  914. gthumb 1300 [001] 34217.697451: do_fork: (c1028460)
  915. gthumb 1300 [001] 34219.085734: do_fork: (c1028460)
  916. gthumb 1300 [000] 34219.121351: do_fork: (c1028460)
  917. gthumb 1300 [001] 34219.264551: do_fork: (c1028460)
  918. pcmanfm 1296 [000] 34219.590380: do_fork: (c1028460)
  919. matchbox-deskto 1197 [001] 34224.955965: do_fork: (c1028460)
  920. matchbox-deskto 1306 [001] 34224.957972: do_fork: (c1028460)
  921. matchbox-termin 1307 [000] 34225.038214: do_fork: (c1028460)
  922. matchbox-termin 1307 [001] 34225.044218: do_fork: (c1028460)
  923. matchbox-termin 1307 [000] 34225.046442: do_fork: (c1028460)
  924. matchbox-deskto 1197 [001] 34237.112138: do_fork: (c1028460)
  925. matchbox-deskto 1311 [001] 34237.114106: do_fork: (c1028460)
  926. gaku 1312 [000] 34237.202388: do_fork: (c1028460)
  927. And using ``perf report`` on the same file, we can see the
  928. call graphs from starting a few programs during those 30 seconds:
  929. .. image:: figures/perf-probe-do_fork-profile.png
  930. :align: center
  931. :width: 70%
  932. .. admonition:: Tying it Together
  933. The trace events subsystem accommodate static and dynamic tracepoints
  934. in exactly the same way --- there's no difference as far as the
  935. infrastructure is concerned. See the ftrace section for more details
  936. on the trace event subsystem.
  937. .. admonition:: Tying it Together
  938. Dynamic tracepoints are implemented under the covers by Kprobes and
  939. Uprobes. Kprobes and Uprobes are also used by and in fact are the
  940. main focus of SystemTap.
  941. perf Documentation
  942. ------------------
  943. Online versions of the manual pages for the commands discussed in this
  944. section can be found here:
  945. - The `'perf stat' manual page <https://linux.die.net/man/1/perf-stat>`__.
  946. - The `'perf record'
  947. manual page <https://linux.die.net/man/1/perf-record>`__.
  948. - The `'perf report'
  949. manual page <https://linux.die.net/man/1/perf-report>`__.
  950. - The `'perf probe' manual page <https://linux.die.net/man/1/perf-probe>`__.
  951. - The `'perf script'
  952. manual page <https://linux.die.net/man/1/perf-script>`__.
  953. - Documentation on using the `'perf script' Python
  954. binding <https://linux.die.net/man/1/perf-script-python>`__.
  955. - The top-level `perf(1) manual page <https://linux.die.net/man/1/perf>`__.
  956. Normally, you should be able to open the manual pages via perf itself
  957. e.g. ``perf help`` or ``perf help record``.
  958. To have the perf manual pages installed on your target, modify your
  959. configuration as follows::
  960. IMAGE_INSTALL:append = " perf perf-doc"
  961. DISTRO_FEATURES:append = " api-documentation"
  962. The manual pages in text form, along with some other files, such as a set
  963. of examples, can also be found in the ``perf`` directory of the kernel tree::
  964. tools/perf/Documentation
  965. There's also a nice perf tutorial on the perf
  966. wiki that goes into more detail than we do here in certain areas: `perf
  967. Tutorial <https://perf.wiki.kernel.org/index.php/Tutorial>`__
  968. ftrace
  969. ======
  970. "ftrace" literally refers to the "ftrace function tracer" but in reality
  971. this encompasses several related tracers along with the
  972. infrastructure that they all make use of.
  973. ftrace Setup
  974. ------------
  975. For this section, we'll assume you've already performed the basic setup
  976. outlined in the ":ref:`profile-manual/intro:General Setup`" section.
  977. ftrace, trace-cmd, and KernelShark run on the target system, and are
  978. ready to go out-of-the-box --- no additional setup is necessary. For the
  979. rest of this section we assume you're connected to the host through SSH and
  980. will be running ftrace on the target. KernelShark is a GUI application and if
  981. you use the ``-X`` option to ``ssh`` you can have the KernelShark GUI run on
  982. the target but display remotely on the host if you want.
  983. Basic ftrace usage
  984. ------------------
  985. "ftrace" essentially refers to everything included in the ``/tracing``
  986. directory of the mounted debugfs filesystem (Yocto follows the standard
  987. convention and mounts it at ``/sys/kernel/debug``). All the files found in
  988. ``/sys/kernel/debug/tracing`` on a Yocto system are::
  989. root@sugarbay:/sys/kernel/debug/tracing# ls
  990. README kprobe_events trace
  991. available_events kprobe_profile trace_clock
  992. available_filter_functions options trace_marker
  993. available_tracers per_cpu trace_options
  994. buffer_size_kb printk_formats trace_pipe
  995. buffer_total_size_kb saved_cmdlines tracing_cpumask
  996. current_tracer set_event tracing_enabled
  997. dyn_ftrace_total_info set_ftrace_filter tracing_on
  998. enabled_functions set_ftrace_notrace tracing_thresh
  999. events set_ftrace_pid
  1000. free_buffer set_graph_function
  1001. The files listed above are used for various purposes
  1002. --- some relate directly to the tracers themselves, others are used to set
  1003. tracing options, and yet others actually contain the tracing output when
  1004. a tracer is in effect. Some of the functions can be guessed from their
  1005. names, others need explanation; in any case, we'll cover some of the
  1006. files we see here below but for an explanation of the others, please see
  1007. the ftrace documentation.
  1008. We'll start by looking at some of the available built-in tracers.
  1009. The ``available_tracers`` file lists the set of available tracers::
  1010. root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers
  1011. blk function_graph function nop
  1012. The ``current_tracer`` file contains the tracer currently in effect::
  1013. root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer
  1014. nop
  1015. The above listing of ``current_tracer`` shows that the
  1016. ``nop`` tracer is in effect, which is just another way of saying that
  1017. there's actually no tracer currently in effect.
  1018. Writing one of the available tracers into ``current_tracer`` makes the
  1019. specified tracer the current tracer::
  1020. root@sugarbay:/sys/kernel/debug/tracing# echo function > current_tracer
  1021. root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer
  1022. function
  1023. The above sets the current tracer to be the ``function`` tracer. This tracer
  1024. traces every function call in the kernel and makes it available as the
  1025. contents of the ``trace`` file. Reading the ``trace`` file lists the
  1026. currently buffered function calls that have been traced by the function
  1027. tracer::
  1028. root@sugarbay:/sys/kernel/debug/tracing# cat trace | less
  1029. # tracer: function
  1030. #
  1031. # entries-in-buffer/entries-written: 310629/766471 #P:8
  1032. #
  1033. # _-----=> irqs-off
  1034. # / _----=> need-resched
  1035. # | / _---=> hardirq/softirq
  1036. # || / _--=> preempt-depth
  1037. # ||| / delay
  1038. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  1039. # | | | |||| | |
  1040. <idle>-0 [004] d..1 470.867169: ktime_get_real <-intel_idle
  1041. <idle>-0 [004] d..1 470.867170: getnstimeofday <-ktime_get_real
  1042. <idle>-0 [004] d..1 470.867171: ns_to_timeval <-intel_idle
  1043. <idle>-0 [004] d..1 470.867171: ns_to_timespec <-ns_to_timeval
  1044. <idle>-0 [004] d..1 470.867172: smp_apic_timer_interrupt <-apic_timer_interrupt
  1045. <idle>-0 [004] d..1 470.867172: native_apic_mem_write <-smp_apic_timer_interrupt
  1046. <idle>-0 [004] d..1 470.867172: irq_enter <-smp_apic_timer_interrupt
  1047. <idle>-0 [004] d..1 470.867172: rcu_irq_enter <-irq_enter
  1048. <idle>-0 [004] d..1 470.867173: rcu_idle_exit_common.isra.33 <-rcu_irq_enter
  1049. <idle>-0 [004] d..1 470.867173: local_bh_disable <-irq_enter
  1050. <idle>-0 [004] d..1 470.867173: add_preempt_count <-local_bh_disable
  1051. <idle>-0 [004] d.s1 470.867174: tick_check_idle <-irq_enter
  1052. <idle>-0 [004] d.s1 470.867174: tick_check_oneshot_broadcast <-tick_check_idle
  1053. <idle>-0 [004] d.s1 470.867174: ktime_get <-tick_check_idle
  1054. <idle>-0 [004] d.s1 470.867174: tick_nohz_stop_idle <-tick_check_idle
  1055. <idle>-0 [004] d.s1 470.867175: update_ts_time_stats <-tick_nohz_stop_idle
  1056. <idle>-0 [004] d.s1 470.867175: nr_iowait_cpu <-update_ts_time_stats
  1057. <idle>-0 [004] d.s1 470.867175: tick_do_update_jiffies64 <-tick_check_idle
  1058. <idle>-0 [004] d.s1 470.867175: _raw_spin_lock <-tick_do_update_jiffies64
  1059. <idle>-0 [004] d.s1 470.867176: add_preempt_count <-_raw_spin_lock
  1060. <idle>-0 [004] d.s2 470.867176: do_timer <-tick_do_update_jiffies64
  1061. <idle>-0 [004] d.s2 470.867176: _raw_spin_lock <-do_timer
  1062. <idle>-0 [004] d.s2 470.867176: add_preempt_count <-_raw_spin_lock
  1063. <idle>-0 [004] d.s3 470.867177: ntp_tick_length <-do_timer
  1064. <idle>-0 [004] d.s3 470.867177: _raw_spin_lock_irqsave <-ntp_tick_length
  1065. .
  1066. .
  1067. .
  1068. Each line in the trace above shows what was happening in the kernel on a given
  1069. CPU, to the level of detail of function calls. Each entry shows the function
  1070. called, followed by its caller (after the arrow).
  1071. The function tracer gives you an extremely detailed idea of what the
  1072. kernel was doing at the point in time the trace was taken, and is a
  1073. great way to learn about how the kernel code works in a dynamic sense.
  1074. .. admonition:: Tying it Together
  1075. The ftrace function tracer is also available from within perf, as the
  1076. ``ftrace:function`` tracepoint.
  1077. It is a little more difficult to follow the call chains than it needs to
  1078. be --- luckily there's a variant of the function tracer that displays the
  1079. call chains explicitly, called the ``function_graph`` tracer::
  1080. root@sugarbay:/sys/kernel/debug/tracing# echo function_graph > current_tracer
  1081. root@sugarbay:/sys/kernel/debug/tracing# cat trace | less
  1082. tracer: function_graph
  1083. CPU DURATION FUNCTION CALLS
  1084. | | | | | | |
  1085. 7) 0.046 us | pick_next_task_fair();
  1086. 7) 0.043 us | pick_next_task_stop();
  1087. 7) 0.042 us | pick_next_task_rt();
  1088. 7) 0.032 us | pick_next_task_fair();
  1089. 7) 0.030 us | pick_next_task_idle();
  1090. 7) | _raw_spin_unlock_irq() {
  1091. 7) 0.033 us | sub_preempt_count();
  1092. 7) 0.258 us | }
  1093. 7) 0.032 us | sub_preempt_count();
  1094. 7) + 13.341 us | } /* __schedule */
  1095. 7) 0.095 us | } /* sub_preempt_count */
  1096. 7) | schedule() {
  1097. 7) | __schedule() {
  1098. 7) 0.060 us | add_preempt_count();
  1099. 7) 0.044 us | rcu_note_context_switch();
  1100. 7) | _raw_spin_lock_irq() {
  1101. 7) 0.033 us | add_preempt_count();
  1102. 7) 0.247 us | }
  1103. 7) | idle_balance() {
  1104. 7) | _raw_spin_unlock() {
  1105. 7) 0.031 us | sub_preempt_count();
  1106. 7) 0.246 us | }
  1107. 7) | update_shares() {
  1108. 7) 0.030 us | __rcu_read_lock();
  1109. 7) 0.029 us | __rcu_read_unlock();
  1110. 7) 0.484 us | }
  1111. 7) 0.030 us | __rcu_read_lock();
  1112. 7) | load_balance() {
  1113. 7) | find_busiest_group() {
  1114. 7) 0.031 us | idle_cpu();
  1115. 7) 0.029 us | idle_cpu();
  1116. 7) 0.035 us | idle_cpu();
  1117. 7) 0.906 us | }
  1118. 7) 1.141 us | }
  1119. 7) 0.022 us | msecs_to_jiffies();
  1120. 7) | load_balance() {
  1121. 7) | find_busiest_group() {
  1122. 7) 0.031 us | idle_cpu();
  1123. .
  1124. .
  1125. .
  1126. 4) 0.062 us | msecs_to_jiffies();
  1127. 4) 0.062 us | __rcu_read_unlock();
  1128. 4) | _raw_spin_lock() {
  1129. 4) 0.073 us | add_preempt_count();
  1130. 4) 0.562 us | }
  1131. 4) + 17.452 us | }
  1132. 4) 0.108 us | put_prev_task_fair();
  1133. 4) 0.102 us | pick_next_task_fair();
  1134. 4) 0.084 us | pick_next_task_stop();
  1135. 4) 0.075 us | pick_next_task_rt();
  1136. 4) 0.062 us | pick_next_task_fair();
  1137. 4) 0.066 us | pick_next_task_idle();
  1138. ------------------------------------------
  1139. 4) kworker-74 => <idle>-0
  1140. ------------------------------------------
  1141. 4) | finish_task_switch() {
  1142. 4) | _raw_spin_unlock_irq() {
  1143. 4) 0.100 us | sub_preempt_count();
  1144. 4) 0.582 us | }
  1145. 4) 1.105 us | }
  1146. 4) 0.088 us | sub_preempt_count();
  1147. 4) ! 100.066 us | }
  1148. .
  1149. .
  1150. .
  1151. 3) | sys_ioctl() {
  1152. 3) 0.083 us | fget_light();
  1153. 3) | security_file_ioctl() {
  1154. 3) 0.066 us | cap_file_ioctl();
  1155. 3) 0.562 us | }
  1156. 3) | do_vfs_ioctl() {
  1157. 3) | drm_ioctl() {
  1158. 3) 0.075 us | drm_ut_debug_printk();
  1159. 3) | i915_gem_pwrite_ioctl() {
  1160. 3) | i915_mutex_lock_interruptible() {
  1161. 3) 0.070 us | mutex_lock_interruptible();
  1162. 3) 0.570 us | }
  1163. 3) | drm_gem_object_lookup() {
  1164. 3) | _raw_spin_lock() {
  1165. 3) 0.080 us | add_preempt_count();
  1166. 3) 0.620 us | }
  1167. 3) | _raw_spin_unlock() {
  1168. 3) 0.085 us | sub_preempt_count();
  1169. 3) 0.562 us | }
  1170. 3) 2.149 us | }
  1171. 3) 0.133 us | i915_gem_object_pin();
  1172. 3) | i915_gem_object_set_to_gtt_domain() {
  1173. 3) 0.065 us | i915_gem_object_flush_gpu_write_domain();
  1174. 3) 0.065 us | i915_gem_object_wait_rendering();
  1175. 3) 0.062 us | i915_gem_object_flush_cpu_write_domain();
  1176. 3) 1.612 us | }
  1177. 3) | i915_gem_object_put_fence() {
  1178. 3) 0.097 us | i915_gem_object_flush_fence.constprop.36();
  1179. 3) 0.645 us | }
  1180. 3) 0.070 us | add_preempt_count();
  1181. 3) 0.070 us | sub_preempt_count();
  1182. 3) 0.073 us | i915_gem_object_unpin();
  1183. 3) 0.068 us | mutex_unlock();
  1184. 3) 9.924 us | }
  1185. 3) + 11.236 us | }
  1186. 3) + 11.770 us | }
  1187. 3) + 13.784 us | }
  1188. 3) | sys_ioctl() {
  1189. As you can see, the ``function_graph`` display is much easier
  1190. to follow. Also note that in addition to the function calls and
  1191. associated braces, other events such as scheduler events are displayed
  1192. in context. In fact, you can freely include any tracepoint available in
  1193. the trace events subsystem described in the next section by just
  1194. enabling those events, and they'll appear in context in the function
  1195. graph display. Quite a powerful tool for understanding kernel dynamics.
  1196. Also notice that there are various annotations on the left hand side of
  1197. the display. For example if the total time it took for a given function
  1198. to execute is above a certain threshold, an exclamation point or plus
  1199. sign appears on the left hand side. Please see the ftrace documentation
  1200. for details on all these fields.
  1201. The 'trace events' Subsystem
  1202. ----------------------------
  1203. One especially important directory contained within the
  1204. ``/sys/kernel/debug/tracing`` directory is the ``events`` subdirectory, which
  1205. contains representations of every tracepoint in the system. Listing out
  1206. the contents of the ``events`` subdirectory, we see mainly another set of
  1207. subdirectories::
  1208. root@sugarbay:/sys/kernel/debug/tracing# cd events
  1209. root@sugarbay:/sys/kernel/debug/tracing/events# ls -al
  1210. drwxr-xr-x 38 root root 0 Nov 14 23:19 .
  1211. drwxr-xr-x 5 root root 0 Nov 14 23:19 ..
  1212. drwxr-xr-x 19 root root 0 Nov 14 23:19 block
  1213. drwxr-xr-x 32 root root 0 Nov 14 23:19 btrfs
  1214. drwxr-xr-x 5 root root 0 Nov 14 23:19 drm
  1215. -rw-r--r-- 1 root root 0 Nov 14 23:19 enable
  1216. drwxr-xr-x 40 root root 0 Nov 14 23:19 ext3
  1217. drwxr-xr-x 79 root root 0 Nov 14 23:19 ext4
  1218. drwxr-xr-x 14 root root 0 Nov 14 23:19 ftrace
  1219. drwxr-xr-x 8 root root 0 Nov 14 23:19 hda
  1220. -r--r--r-- 1 root root 0 Nov 14 23:19 header_event
  1221. -r--r--r-- 1 root root 0 Nov 14 23:19 header_page
  1222. drwxr-xr-x 25 root root 0 Nov 14 23:19 i915
  1223. drwxr-xr-x 7 root root 0 Nov 14 23:19 irq
  1224. drwxr-xr-x 12 root root 0 Nov 14 23:19 jbd
  1225. drwxr-xr-x 14 root root 0 Nov 14 23:19 jbd2
  1226. drwxr-xr-x 14 root root 0 Nov 14 23:19 kmem
  1227. drwxr-xr-x 7 root root 0 Nov 14 23:19 module
  1228. drwxr-xr-x 3 root root 0 Nov 14 23:19 napi
  1229. drwxr-xr-x 6 root root 0 Nov 14 23:19 net
  1230. drwxr-xr-x 3 root root 0 Nov 14 23:19 oom
  1231. drwxr-xr-x 12 root root 0 Nov 14 23:19 power
  1232. drwxr-xr-x 3 root root 0 Nov 14 23:19 printk
  1233. drwxr-xr-x 8 root root 0 Nov 14 23:19 random
  1234. drwxr-xr-x 4 root root 0 Nov 14 23:19 raw_syscalls
  1235. drwxr-xr-x 3 root root 0 Nov 14 23:19 rcu
  1236. drwxr-xr-x 6 root root 0 Nov 14 23:19 rpm
  1237. drwxr-xr-x 20 root root 0 Nov 14 23:19 sched
  1238. drwxr-xr-x 7 root root 0 Nov 14 23:19 scsi
  1239. drwxr-xr-x 4 root root 0 Nov 14 23:19 signal
  1240. drwxr-xr-x 5 root root 0 Nov 14 23:19 skb
  1241. drwxr-xr-x 4 root root 0 Nov 14 23:19 sock
  1242. drwxr-xr-x 10 root root 0 Nov 14 23:19 sunrpc
  1243. drwxr-xr-x 538 root root 0 Nov 14 23:19 syscalls
  1244. drwxr-xr-x 4 root root 0 Nov 14 23:19 task
  1245. drwxr-xr-x 14 root root 0 Nov 14 23:19 timer
  1246. drwxr-xr-x 3 root root 0 Nov 14 23:19 udp
  1247. drwxr-xr-x 21 root root 0 Nov 14 23:19 vmscan
  1248. drwxr-xr-x 3 root root 0 Nov 14 23:19 vsyscall
  1249. drwxr-xr-x 6 root root 0 Nov 14 23:19 workqueue
  1250. drwxr-xr-x 26 root root 0 Nov 14 23:19 writeback
  1251. Each one of these subdirectories
  1252. corresponds to a "subsystem" and contains yet again more subdirectories,
  1253. each one of those finally corresponding to a tracepoint. For example,
  1254. here are the contents of the ``kmem`` subsystem::
  1255. root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem
  1256. root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al
  1257. drwxr-xr-x 14 root root 0 Nov 14 23:19 .
  1258. drwxr-xr-x 38 root root 0 Nov 14 23:19 ..
  1259. -rw-r--r-- 1 root root 0 Nov 14 23:19 enable
  1260. -rw-r--r-- 1 root root 0 Nov 14 23:19 filter
  1261. drwxr-xr-x 2 root root 0 Nov 14 23:19 kfree
  1262. drwxr-xr-x 2 root root 0 Nov 14 23:19 kmalloc
  1263. drwxr-xr-x 2 root root 0 Nov 14 23:19 kmalloc_node
  1264. drwxr-xr-x 2 root root 0 Nov 14 23:19 kmem_cache_alloc
  1265. drwxr-xr-x 2 root root 0 Nov 14 23:19 kmem_cache_alloc_node
  1266. drwxr-xr-x 2 root root 0 Nov 14 23:19 kmem_cache_free
  1267. drwxr-xr-x 2 root root 0 Nov 14 23:19 mm_page_alloc
  1268. drwxr-xr-x 2 root root 0 Nov 14 23:19 mm_page_alloc_extfrag
  1269. drwxr-xr-x 2 root root 0 Nov 14 23:19 mm_page_alloc_zone_locked
  1270. drwxr-xr-x 2 root root 0 Nov 14 23:19 mm_page_free
  1271. drwxr-xr-x 2 root root 0 Nov 14 23:19 mm_page_free_batched
  1272. drwxr-xr-x 2 root root 0 Nov 14 23:19 mm_page_pcpu_drain
  1273. Let's see what's inside the subdirectory for a
  1274. specific tracepoint, in this case the one for ``kmalloc``::
  1275. root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc
  1276. root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al
  1277. drwxr-xr-x 2 root root 0 Nov 14 23:19 .
  1278. drwxr-xr-x 14 root root 0 Nov 14 23:19 ..
  1279. -rw-r--r-- 1 root root 0 Nov 14 23:19 enable
  1280. -rw-r--r-- 1 root root 0 Nov 14 23:19 filter
  1281. -r--r--r-- 1 root root 0 Nov 14 23:19 format
  1282. -r--r--r-- 1 root root 0 Nov 14 23:19 id
  1283. The ``format`` file for the
  1284. tracepoint describes the event in memory, which is used by the various
  1285. tracing tools that now make use of these tracepoint to parse the event
  1286. and make sense of it, along with a ``print fmt`` field that allows tools
  1287. like ftrace to display the event as text. The format of the
  1288. ``kmalloc`` event looks like::
  1289. root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format
  1290. name: kmalloc
  1291. ID: 313
  1292. format:
  1293. field:unsigned short common_type; offset:0; size:2; signed:0;
  1294. field:unsigned char common_flags; offset:2; size:1; signed:0;
  1295. field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
  1296. field:int common_pid; offset:4; size:4; signed:1;
  1297. field:int common_padding; offset:8; size:4; signed:1;
  1298. field:unsigned long call_site; offset:16; size:8; signed:0;
  1299. field:const void * ptr; offset:24; size:8; signed:0;
  1300. field:size_t bytes_req; offset:32; size:8; signed:0;
  1301. field:size_t bytes_alloc; offset:40; size:8; signed:0;
  1302. field:gfp_t gfp_flags; offset:48; size:4; signed:0;
  1303. print fmt: "call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s", REC->call_site, REC->ptr, REC->bytes_req, REC->bytes_alloc,
  1304. (REC->gfp_flags) ? __print_flags(REC->gfp_flags, "|", {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((
  1305. gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((
  1306. gfp_t)0x400000u)), "GFP_TRANSHUGE"}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((
  1307. gfp_t)0x02u) | (( gfp_t)0x08u)), "GFP_HIGHUSER_MOVABLE"}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((
  1308. gfp_t)0x20000u) | (( gfp_t)0x02u)), "GFP_HIGHUSER"}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((
  1309. gfp_t)0x20000u)), "GFP_USER"}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY"},
  1310. {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), "GFP_KERNEL"}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)),
  1311. "GFP_NOFS"}, {(unsigned long)((( gfp_t)0x20u)), "GFP_ATOMIC"}, {(unsigned long)((( gfp_t)0x10u)), "GFP_NOIO"}, {(unsigned long)((
  1312. gfp_t)0x20u), "GFP_HIGH"}, {(unsigned long)(( gfp_t)0x10u), "GFP_WAIT"}, {(unsigned long)(( gfp_t)0x40u), "GFP_IO"}, {(unsigned long)((
  1313. gfp_t)0x100u), "GFP_COLD"}, {(unsigned long)(( gfp_t)0x200u), "GFP_NOWARN"}, {(unsigned long)(( gfp_t)0x400u), "GFP_REPEAT"}, {(unsigned
  1314. long)(( gfp_t)0x800u), "GFP_NOFAIL"}, {(unsigned long)(( gfp_t)0x1000u), "GFP_NORETRY"}, {(unsigned long)(( gfp_t)0x4000u), "GFP_COMP"},
  1315. {(unsigned long)(( gfp_t)0x8000u), "GFP_ZERO"}, {(unsigned long)(( gfp_t)0x10000u), "GFP_NOMEMALLOC"}, {(unsigned long)(( gfp_t)0x20000u),
  1316. "GFP_HARDWALL"}, {(unsigned long)(( gfp_t)0x40000u), "GFP_THISNODE"}, {(unsigned long)(( gfp_t)0x80000u), "GFP_RECLAIMABLE"}, {(unsigned
  1317. long)(( gfp_t)0x08u), "GFP_MOVABLE"}, {(unsigned long)(( gfp_t)0), "GFP_NOTRACK"}, {(unsigned long)(( gfp_t)0x400000u), "GFP_NO_KSWAPD"},
  1318. {(unsigned long)(( gfp_t)0x800000u), "GFP_OTHER_NODE"} ) : "GFP_NOWAIT"
  1319. The ``enable`` file
  1320. in the tracepoint directory is what allows the user (or tools such as
  1321. ``trace-cmd``) to actually turn the tracepoint on and off. When enabled, the
  1322. corresponding tracepoint will start appearing in the ftrace ``trace`` file
  1323. described previously. For example, this turns on the ``kmalloc`` tracepoint::
  1324. root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 > enable
  1325. At the moment, we're not interested in the function tracer or
  1326. some other tracer that might be in effect, so we first turn it off, but
  1327. if we do that, we still need to turn tracing on in order to see the
  1328. events in the output buffer::
  1329. root@sugarbay:/sys/kernel/debug/tracing# echo nop > current_tracer
  1330. root@sugarbay:/sys/kernel/debug/tracing# echo 1 > tracing_on
  1331. Now, if we look at the ``trace`` file, we see nothing
  1332. but the ``kmalloc`` events we just turned on::
  1333. root@sugarbay:/sys/kernel/debug/tracing# cat trace | less
  1334. # tracer: nop
  1335. #
  1336. # entries-in-buffer/entries-written: 1897/1897 #P:8
  1337. #
  1338. # _-----=> irqs-off
  1339. # / _----=> need-resched
  1340. # | / _---=> hardirq/softirq
  1341. # || / _--=> preempt-depth
  1342. # ||| / delay
  1343. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  1344. # | | | |||| | |
  1345. dropbear-1465 [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL
  1346. <idle>-0 [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC
  1347. <idle>-0 [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC
  1348. matchbox-termin-1361 [001] ...1 18154.755472: kmalloc: call_site=ffffffff81614050 ptr=ffff88006d5f0e00 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_KERNEL|GFP_REPEAT
  1349. Xorg-1264 [002] ...1 18154.755581: kmalloc: call_site=ffffffff8141abe8 ptr=ffff8800734f4cc0 bytes_req=168 bytes_alloc=192 gfp_flags=GFP_KERNEL|GFP_NOWARN|GFP_NORETRY
  1350. Xorg-1264 [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO
  1351. Xorg-1264 [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO
  1352. matchbox-termin-1361 [001] ...1 18155.354594: kmalloc: call_site=ffffffff81614050 ptr=ffff88006db35400 bytes_req=576 bytes_alloc=1024 gfp_flags=GFP_KERNEL|GFP_REPEAT
  1353. Xorg-1264 [002] ...1 18155.354703: kmalloc: call_site=ffffffff8141abe8 ptr=ffff8800734f4cc0 bytes_req=168 bytes_alloc=192 gfp_flags=GFP_KERNEL|GFP_NOWARN|GFP_NORETRY
  1354. Xorg-1264 [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO
  1355. Xorg-1264 [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO
  1356. <idle>-0 [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC
  1357. dropbear-1465 [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL
  1358. <idle>-0 [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC
  1359. <idle>-0 [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC
  1360. dropbear-1465 [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL
  1361. <idle>-0 [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC
  1362. <idle>-0 [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC
  1363. dropbear-1465 [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL
  1364. <idle>-0 [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC
  1365. matchbox-termin-1361 [001] ...1 18155.953667: kmalloc: call_site=ffffffff81614050 ptr=ffff88006d5f2000 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_KERNEL|GFP_REPEAT
  1366. Xorg-1264 [002] ...1 18155.953775: kmalloc: call_site=ffffffff8141abe8 ptr=ffff8800734f4cc0 bytes_req=168 bytes_alloc=192 gfp_flags=GFP_KERNEL|GFP_NOWARN|GFP_NORETRY
  1367. Xorg-1264 [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO
  1368. Xorg-1264 [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO
  1369. <idle>-0 [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC
  1370. dropbear-1465 [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL
  1371. <idle>-0 [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC
  1372. <idle>-0 [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC
  1373. dropbear-1465 [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_http://rostedt.homelinux.com/kernelshark/req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL
  1374. <idle>-0 [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC
  1375. matchbox-termin-1361 [001] ...1 18156.552800: kmalloc: call_site=ffffffff81614050 ptr=ffff88006db34800 bytes_req=576 bytes_alloc=1024 gfp_flags=GFP_KERNEL|GFP_REPEAT
  1376. To again disable the ``kmalloc`` event, we need to send ``0`` to the ``enable`` file::
  1377. root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 > enable
  1378. You can enable any number of events or complete subsystems (by
  1379. using the ``enable`` file in the subsystem directory) and get an
  1380. arbitrarily fine-grained idea of what's going on in the system by
  1381. enabling as many of the appropriate tracepoints as applicable.
  1382. Several tools described in this How-to do just that, including
  1383. ``trace-cmd`` and KernelShark in the next section.
  1384. .. admonition:: Tying it Together
  1385. These tracepoints and their representation are used not only by
  1386. ftrace, but by many of the other tools covered in this document and
  1387. they form a central point of integration for the various tracers
  1388. available in Linux. They form a central part of the instrumentation
  1389. for the following tools: perf, LTTng, ftrace, blktrace and SystemTap
  1390. .. admonition:: Tying it Together
  1391. Eventually all the special-purpose tracers currently available in
  1392. ``/sys/kernel/debug/tracing`` will be removed and replaced with
  1393. equivalent tracers based on the "trace events" subsystem.
  1394. trace-cmd / KernelShark
  1395. -----------------------
  1396. trace-cmd is essentially an extensive command-line "wrapper" interface
  1397. that hides the details of all the individual files in
  1398. ``/sys/kernel/debug/tracing``, allowing users to specify specific particular
  1399. events within the ``/sys/kernel/debug/tracing/events/`` subdirectory and to
  1400. collect traces and avoid having to deal with those details directly.
  1401. As yet another layer on top of that, KernelShark provides a GUI that
  1402. allows users to start and stop traces and specify sets of events using
  1403. an intuitive interface, and view the output as both trace events and as
  1404. a per-CPU graphical display. It directly uses trace-cmd as the
  1405. plumbing that accomplishes all that underneath the covers (and actually
  1406. displays the trace-cmd command it uses, as we'll see).
  1407. To start a trace using KernelShark, first start this tool::
  1408. root@sugarbay:~# kernelshark
  1409. Then open up the ``Capture`` dialog by choosing from the KernelShark menu::
  1410. Capture | Record
  1411. That will display the following dialog, which allows you to choose one or more
  1412. events (or even entire subsystems) to trace:
  1413. .. image:: figures/kernelshark-choose-events.png
  1414. :align: center
  1415. :width: 70%
  1416. Note that these are exactly the same sets of events described in the
  1417. previous trace events subsystem section, and in fact is where trace-cmd
  1418. gets them for KernelShark.
  1419. In the above screenshot, we've decided to explore the graphics subsystem
  1420. a bit and so have chosen to trace all the tracepoints contained within
  1421. the ``i915`` and ``drm`` subsystems.
  1422. After doing that, we can start and stop the trace using the ``Run`` and
  1423. ``Stop`` button on the lower right corner of the dialog (the same button
  1424. will turn into the 'Stop' button after the trace has started):
  1425. .. image:: figures/kernelshark-output-display.png
  1426. :align: center
  1427. :width: 70%
  1428. Notice that the right pane shows the exact trace-cmd command-line
  1429. that's used to run the trace, along with the results of the trace-cmd
  1430. run.
  1431. Once the ``Stop`` button is pressed, the graphical view magically fills up
  1432. with a colorful per-CPU display of the trace data, along with the
  1433. detailed event listing below that:
  1434. .. image:: figures/kernelshark-i915-display.png
  1435. :align: center
  1436. :width: 70%
  1437. Here's another example, this time a display resulting from tracing ``all
  1438. events``:
  1439. .. image:: figures/kernelshark-all.png
  1440. :align: center
  1441. :width: 70%
  1442. The tool is pretty self-explanatory, but for more detailed information
  1443. on navigating through the data, see the `KernelShark
  1444. website <https://kernelshark.org/Documentation.html>`__.
  1445. ftrace Documentation
  1446. --------------------
  1447. The documentation for ftrace can be found in the kernel Documentation
  1448. directory::
  1449. Documentation/trace/ftrace.txt
  1450. The documentation for the trace event subsystem can also be found in the kernel
  1451. Documentation directory::
  1452. Documentation/trace/events.txt
  1453. A nice series of articles on using ftrace and trace-cmd are available at LWN:
  1454. - `Debugging the kernel using ftrace - part
  1455. 1 <https://lwn.net/Articles/365835/>`__
  1456. - `Debugging the kernel using ftrace - part
  1457. 2 <https://lwn.net/Articles/366796/>`__
  1458. - `Secrets of the ftrace function
  1459. tracer <https://lwn.net/Articles/370423/>`__
  1460. - `trace-cmd: A front-end for
  1461. ftrace <https://lwn.net/Articles/410200/>`__
  1462. See also `KernelShark's documentation <https://kernelshark.org/Documentation.html>`__
  1463. for further usage details.
  1464. An amusing yet useful README (a tracing mini-How-to) can be found in
  1465. ``/sys/kernel/debug/tracing/README``.
  1466. SystemTap
  1467. =========
  1468. SystemTap is a system-wide script-based tracing and profiling tool.
  1469. SystemTap scripts are C-like programs that are executed in the kernel to
  1470. gather / print / aggregate data extracted from the context they end up being
  1471. called under.
  1472. For example, this probe from the `SystemTap
  1473. tutorial <https://sourceware.org/systemtap/tutorial/>`__ just prints a
  1474. line every time any process on the system runs ``open()`` on a file. For each line,
  1475. it prints the executable name of the program that opened the file, along
  1476. with its PID, and the name of the file it opened (or tried to open), which it
  1477. extracts from the argument string (``argstr``) of the ``open`` system call.
  1478. .. code-block:: none
  1479. probe syscall.open
  1480. {
  1481. printf ("%s(%d) open (%s)\n", execname(), pid(), argstr)
  1482. }
  1483. probe timer.ms(4000) # after 4 seconds
  1484. {
  1485. exit ()
  1486. }
  1487. Normally, to execute this
  1488. probe, you'd just install SystemTap on the system you want to probe,
  1489. and directly run the probe on that system e.g. assuming the name of the
  1490. file containing the above text is ``trace_open.stp``::
  1491. # stap trace_open.stp
  1492. What SystemTap does under the covers to run this probe is 1) parse and
  1493. convert the probe to an equivalent "C" form, 2) compile the "C" form
  1494. into a kernel module, 3) insert the module into the kernel, which arms
  1495. it, and 4) collect the data generated by the probe and display it to the
  1496. user.
  1497. In order to accomplish steps 1 and 2, the ``stap`` program needs access to
  1498. the kernel build system that produced the kernel that the probed system
  1499. is running. In the case of a typical embedded system (the "target"), the
  1500. kernel build system unfortunately isn't typically part of the image
  1501. running on the target. It is normally available on the "host" system
  1502. that produced the target image however; in such cases, steps 1 and 2 are
  1503. executed on the host system, and steps 3 and 4 are executed on the
  1504. target system, using only the SystemTap "runtime".
  1505. The SystemTap support in Yocto assumes that only steps 3 and 4 are run
  1506. on the target; it is possible to do everything on the target, but this
  1507. section assumes only the typical embedded use-case.
  1508. Therefore, what you need to do in order to run a SystemTap script on
  1509. the target is to 1) on the host system, compile the probe into a kernel
  1510. module that makes sense to the target, 2) copy the module onto the
  1511. target system and 3) insert the module into the target kernel, which
  1512. arms it, and 4) collect the data generated by the probe and display it
  1513. to the user.
  1514. SystemTap Setup
  1515. ---------------
  1516. Those are many steps and details, but fortunately Yocto
  1517. includes a script called ``crosstap`` that will take care of those
  1518. details, allowing you to just execute a SystemTap script on the remote
  1519. target, with arguments if necessary.
  1520. In order to do this from a remote host, however, you need to have access
  1521. to the build for the image you booted. The ``crosstap`` script provides
  1522. details on how to do this if you run the script on the host without
  1523. having done a build::
  1524. $ crosstap root@192.168.1.88 trace_open.stp
  1525. Error: No target kernel build found.
  1526. Did you forget to create a local build of your image?
  1527. 'crosstap' requires a local SDK build of the target system
  1528. (or a build that includes 'tools-profile') in order to build
  1529. kernel modules that can probe the target system.
  1530. Practically speaking, that means you need to do the following:
  1531. - If you're running a pre-built image, download the release
  1532. and/or BSP tarballs used to build the image.
  1533. - If you're working from git sources, just clone the metadata
  1534. and BSP layers needed to build the image you'll be booting.
  1535. - Make sure you're properly set up to build a new image (see
  1536. the BSP README and/or the widely available basic documentation
  1537. that discusses how to build images).
  1538. - Build an ``-sdk`` version of the image e.g.::
  1539. $ bitbake core-image-sato-sdk
  1540. - Or build a non-SDK image but include the profiling tools
  1541. (edit ``local.conf`` and add ``tools-profile`` to the end of
  1542. :term:`EXTRA_IMAGE_FEATURES` variable)::
  1543. $ bitbake core-image-sato
  1544. Once you've build the image on the host system, you're ready to
  1545. boot it (or the equivalent pre-built image) and use ``crosstap``
  1546. to probe it (you need to source the environment as usual first)::
  1547. $ source oe-init-build-env
  1548. $ cd ~/my/systemtap/scripts
  1549. $ crosstap root@192.168.1.xxx myscript.stp
  1550. .. note::
  1551. SystemTap, which uses ``crosstap``, assumes you can establish an SSH
  1552. connection to the remote target. Please refer to the crosstap wiki
  1553. page for details on verifying SSH connections. Also, the ability to SSH
  1554. into the target system is not enabled by default in ``*-minimal`` images.
  1555. Therefore, what you need to do is build an SDK image or image with
  1556. ``tools-profile`` as detailed in the ":ref:`profile-manual/intro:General Setup`"
  1557. section of this manual, and boot the resulting target image.
  1558. .. note::
  1559. If you have a :term:`Build Directory` containing multiple machines, you need
  1560. to have the :term:`MACHINE` you're connecting to selected in ``local.conf``, and
  1561. the kernel in that machine's :term:`Build Directory` must match the kernel on
  1562. the booted system exactly, or you'll get the above ``crosstap`` message
  1563. when you try to call a script.
  1564. Running a Script on a Target
  1565. ----------------------------
  1566. Once you've done that, you should be able to run a SystemTap script on
  1567. the target::
  1568. $ cd /path/to/yocto
  1569. $ source oe-init-build-env
  1570. ### Shell environment set up for builds. ###
  1571. You can now run 'bitbake <target>'
  1572. Common targets are:
  1573. core-image-minimal
  1574. core-image-sato
  1575. meta-toolchain
  1576. meta-ide-support
  1577. You can also run generated QEMU images with a command like 'runqemu qemux86-64'
  1578. Once you've done that, you can ``cd`` to whatever
  1579. directory contains your scripts and use ``crosstap`` to run the script::
  1580. $ cd /path/to/my/systemap/script
  1581. $ crosstap root@192.168.7.2 trace_open.stp
  1582. If you get an error connecting to the target e.g.::
  1583. $ crosstap root@192.168.7.2 trace_open.stp
  1584. error establishing ssh connection on remote 'root@192.168.7.2'
  1585. Try connecting to the target through SSH and see what happens::
  1586. $ ssh root@192.168.7.2
  1587. Connection problems are often due specifying a wrong IP address or having a ``host key
  1588. verification error``.
  1589. If everything worked as planned, you should see something like this
  1590. (enter the password when prompted, or press enter if it's set up to use
  1591. no password):
  1592. .. code-block:: none
  1593. $ crosstap root@192.168.7.2 trace_open.stp
  1594. root@192.168.7.2's password:
  1595. matchbox-termin(1036) open ("/tmp/vte3FS2LW", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)
  1596. matchbox-termin(1036) open ("/tmp/vteJMC7LW", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)
  1597. SystemTap Documentation
  1598. -----------------------
  1599. The SystemTap language reference can be found here: `SystemTap Language
  1600. Reference <https://sourceware.org/systemtap/langref/>`__
  1601. Links to other SystemTap documents, tutorials, and examples can be found
  1602. here: `SystemTap documentation
  1603. page <https://sourceware.org/systemtap/documentation.html>`__
  1604. Sysprof
  1605. =======
  1606. Sysprof is an easy to use system-wide profiler that consists of a
  1607. single window with three panes and a few buttons which allow you to
  1608. start, stop, and view the profile from one place.
  1609. Sysprof Setup
  1610. -------------
  1611. For this section, we'll assume you've already performed the basic setup
  1612. outlined in the ":ref:`profile-manual/intro:General Setup`" section.
  1613. Sysprof is a GUI-based application that runs on the target system. For the rest
  1614. of this document we assume you're connected to the host through SSH and will be
  1615. running Sysprof on the target (you can use the ``-X`` option to ``ssh`` and
  1616. have the Sysprof GUI run on the target but display remotely on the host
  1617. if you want).
  1618. Basic Sysprof Usage
  1619. -------------------
  1620. To start profiling the system, you just press the ``Start`` button. To
  1621. stop profiling and to start viewing the profile data in one easy step,
  1622. press the ``Profile`` button.
  1623. Once you've pressed the profile button, the three panes will fill up
  1624. with profiling data:
  1625. .. image:: figures/sysprof-copy-to-user.png
  1626. :align: center
  1627. :width: 70%
  1628. The left pane shows a list of functions and processes. Selecting one of
  1629. those expands that function in the right pane, showing all its callees.
  1630. Note that this caller-oriented display is essentially the inverse of
  1631. perf's default callee-oriented call chain display.
  1632. In the screenshot above, we're focusing on ``__copy_to_user_ll()`` and
  1633. looking up the call chain we can see that one of the callers of
  1634. ``__copy_to_user_ll`` is ``sys_read()`` and the complete call path between them.
  1635. Notice that this is essentially a portion of the same information we saw
  1636. in the perf display shown in the perf section of this page.
  1637. .. image:: figures/sysprof-copy-from-user.png
  1638. :align: center
  1639. :width: 70%
  1640. Similarly, the above is a snapshot of the Sysprof display of a
  1641. ``copy-from-user`` call chain.
  1642. Finally, looking at the third Sysprof pane in the lower left, we can see
  1643. a list of all the callers of a particular function selected in the top
  1644. left pane. In this case, the lower pane is showing all the callers of
  1645. ``__mark_inode_dirty``:
  1646. .. image:: figures/sysprof-callers.png
  1647. :align: center
  1648. :width: 70%
  1649. Double-clicking on one of those functions will in turn change the focus
  1650. to the selected function, and so on.
  1651. .. admonition:: Tying it Together
  1652. If you like Sysprof's ``caller-oriented`` display, you may be able to
  1653. approximate it in other tools as well. For example, ``perf report`` has
  1654. the ``-g`` (``--call-graph``) option that you can experiment with; one of the
  1655. options is ``caller`` for an inverted caller-based call graph display.
  1656. Sysprof Documentation
  1657. ---------------------
  1658. There doesn't seem to be any documentation for Sysprof, but maybe that's
  1659. because it's pretty self-explanatory. The Sysprof website, however, is here:
  1660. `Sysprof, System-wide Performance Profiler for Linux <http://sysprof.com/>`__
  1661. LTTng (Linux Trace Toolkit, next generation)
  1662. ============================================
  1663. LTTng Setup
  1664. -----------
  1665. For this section, we'll assume you've already performed the basic setup
  1666. outlined in the ":ref:`profile-manual/intro:General Setup`" section.
  1667. LTTng is run on the target system by connecting to it through SSH.
  1668. Collecting and Viewing Traces
  1669. -----------------------------
  1670. Once you've applied the above commits and built and booted your image
  1671. (you need to build the ``core-image-sato-sdk`` image or use one of the other
  1672. methods described in the ":ref:`profile-manual/intro:General Setup`" section), you're ready to start
  1673. tracing.
  1674. Collecting and viewing a trace on the target (inside a shell)
  1675. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1676. First, from the host, connect to the target through SSH::
  1677. $ ssh -l root 192.168.1.47
  1678. The authenticity of host '192.168.1.47 (192.168.1.47)' can't be established.
  1679. RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.
  1680. Are you sure you want to continue connecting (yes/no)? yes
  1681. Warning: Permanently added '192.168.1.47' (RSA) to the list of known hosts.
  1682. root@192.168.1.47's password:
  1683. Once on the target, use these steps to create a trace::
  1684. root@crownbay:~# lttng create
  1685. Spawning a session daemon
  1686. Session auto-20121015-232120 created.
  1687. Traces will be written in /home/root/lttng-traces/auto-20121015-232120
  1688. Enable the events you want to trace (in this case all kernel events)::
  1689. root@crownbay:~# lttng enable-event --kernel --all
  1690. All kernel events are enabled in channel channel0
  1691. Start the trace::
  1692. root@crownbay:~# lttng start
  1693. Tracing started for session auto-20121015-232120
  1694. And then stop the trace after awhile or after running a particular workload that
  1695. you want to trace::
  1696. root@crownbay:~# lttng stop
  1697. Tracing stopped for session auto-20121015-232120
  1698. You can now view the trace in text form on the target::
  1699. root@crownbay:~# lttng view
  1700. [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }
  1701. [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }
  1702. [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }
  1703. [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }
  1704. [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }
  1705. [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }
  1706. [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }
  1707. [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = "lttng-consumerd", tid = 1193, runtime = 681660, vruntime = 43367983388 }
  1708. [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = "lttng-consumerd", tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }
  1709. [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }
  1710. [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }
  1711. [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }
  1712. [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }
  1713. [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }
  1714. [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }
  1715. [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }
  1716. [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }
  1717. [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = "lttng-consumerd", tid = 1193, runtime = 330710, vruntime = 43368314098 }
  1718. [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = "lttng-sessiond", tid = 1181, runtime = 1015313, vruntime = 36976733240 }
  1719. [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }
  1720. [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }
  1721. [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }
  1722. [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }
  1723. [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }
  1724. [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }
  1725. [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }
  1726. [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }
  1727. [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }
  1728. [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }
  1729. [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = "lttng-consumerd", tid = 1193, runtime = 49237, vruntime = 43368363335 }
  1730. [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = "lttng-sessiond", tid = 1181, runtime = 45121, vruntime = 36976778361 }
  1731. [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = "kworker/1:1", tid = 21, delay = 9451318 }
  1732. [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = "kworker/0:0", tid = 4, delay = 9958820 }
  1733. [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = "kworker/0:0", tid = 4, prio = 120, success = 1, target_cpu = 0 }
  1734. [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = "kworker/1:1", tid = 21, prio = 120, success = 1, target_cpu = 1 }
  1735. [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }
  1736. [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }
  1737. .
  1738. .
  1739. .
  1740. You can now safely destroy the trace
  1741. session (note that this doesn't delete the trace --- it's still there in
  1742. ``~/lttng-traces``)::
  1743. root@crownbay:~# lttng destroy
  1744. Session auto-20121015-232120 destroyed at /home/root
  1745. Note that the trace is saved in a directory of the same name as returned by
  1746. ``lttng create``, under the ``~/lttng-traces`` directory (note that you can change this by
  1747. supplying your own name to ``lttng create``)::
  1748. root@crownbay:~# ls -al ~/lttng-traces
  1749. drwxrwx--- 3 root root 1024 Oct 15 23:21 .
  1750. drwxr-xr-x 5 root root 1024 Oct 15 23:57 ..
  1751. drwxrwx--- 3 root root 1024 Oct 15 23:21 auto-20121015-232120
  1752. Collecting and viewing a user space trace on the target (inside a shell)
  1753. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1754. For LTTng user space tracing, you need to have a properly instrumented
  1755. user space program. For this example, we'll use the ``hello`` test program
  1756. generated by the ``lttng-ust`` build.
  1757. The ``hello`` test program isn't installed on the root filesystem by the ``lttng-ust``
  1758. build, so we need to copy it over manually. First ``cd`` into the build
  1759. directory that contains the ``hello`` executable::
  1760. $ cd build/tmp/work/core2_32-poky-linux/lttng-ust/2.0.5-r0/git/tests/hello/.libs
  1761. Copy that over to the target machine::
  1762. $ scp hello root@192.168.1.20:
  1763. You now have the instrumented LTTng "hello world" test program on the
  1764. target, ready to test.
  1765. First, from the host, connect to the target through SSH::
  1766. $ ssh -l root 192.168.1.47
  1767. The authenticity of host '192.168.1.47 (192.168.1.47)' can't be established.
  1768. RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.
  1769. Are you sure you want to continue connecting (yes/no)? yes
  1770. Warning: Permanently added '192.168.1.47' (RSA) to the list of known hosts.
  1771. root@192.168.1.47's password:
  1772. Once on the target, use these steps to create a trace::
  1773. root@crownbay:~# lttng create
  1774. Session auto-20190303-021943 created.
  1775. Traces will be written in /home/root/lttng-traces/auto-20190303-021943
  1776. Enable the events you want to trace (in this case all user space events)::
  1777. root@crownbay:~# lttng enable-event --userspace --all
  1778. All UST events are enabled in channel channel0
  1779. Start the trace::
  1780. root@crownbay:~# lttng start
  1781. Tracing started for session auto-20190303-021943
  1782. Run the instrumented "hello world" program::
  1783. root@crownbay:~# ./hello
  1784. Hello, World!
  1785. Tracing... done.
  1786. And then stop the trace after awhile or after running a particular workload
  1787. that you want to trace::
  1788. root@crownbay:~# lttng stop
  1789. Tracing stopped for session auto-20190303-021943
  1790. You can now view the trace in text form on the target::
  1791. root@crownbay:~# lttng view
  1792. [02:31:14.906146544] (+?.?????????) hello:1424 ust_tests_hello:tptest: { cpu_id = 1 }, { intfield = 0, intfield2 = 0x0, longfield = 0, netintfield = 0, netintfieldhex = 0x0, arrfield1 = [ [0] = 1, [1] = 2, [2] = 3 ], arrfield2 = "test", _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = "test", stringfield = "test", floatfield = 2222, doublefield = 2, boolfield = 1 }
  1793. [02:31:14.906170360] (+0.000023816) hello:1424 ust_tests_hello:tptest: { cpu_id = 1 }, { intfield = 1, intfield2 = 0x1, longfield = 1, netintfield = 1, netintfieldhex = 0x1, arrfield1 = [ [0] = 1, [1] = 2, [2] = 3 ], arrfield2 = "test", _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = "test", stringfield = "test", floatfield = 2222, doublefield = 2, boolfield = 1 }
  1794. [02:31:14.906183140] (+0.000012780) hello:1424 ust_tests_hello:tptest: { cpu_id = 1 }, { intfield = 2, intfield2 = 0x2, longfield = 2, netintfield = 2, netintfieldhex = 0x2, arrfield1 = [ [0] = 1, [1] = 2, [2] = 3 ], arrfield2 = "test", _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = "test", stringfield = "test", floatfield = 2222, doublefield = 2, boolfield = 1 }
  1795. [02:31:14.906194385] (+0.000011245) hello:1424 ust_tests_hello:tptest: { cpu_id = 1 }, { intfield = 3, intfield2 = 0x3, longfield = 3, netintfield = 3, netintfieldhex = 0x3, arrfield1 = [ [0] = 1, [1] = 2, [2] = 3 ], arrfield2 = "test", _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = "test", stringfield = "test", floatfield = 2222, doublefield = 2, boolfield = 1 }
  1796. .
  1797. .
  1798. .
  1799. You can now safely destroy the trace session (note that this doesn't delete the
  1800. trace --- it's still there in ``~/lttng-traces``)::
  1801. root@crownbay:~# lttng destroy
  1802. Session auto-20190303-021943 destroyed at /home/root
  1803. LTTng Documentation
  1804. -------------------
  1805. You can find the primary LTTng Documentation on the `LTTng
  1806. Documentation <https://lttng.org/docs/>`__ site. The documentation on
  1807. this site is appropriate for intermediate to advanced software
  1808. developers who are working in a Linux environment and are interested in
  1809. efficient software tracing.
  1810. For information on LTTng in general, visit the `LTTng
  1811. Project <https://lttng.org/lttng2.0>`__ site. You can find a "Getting
  1812. Started" link on this site that takes you to an LTTng Quick Start.
  1813. blktrace
  1814. ========
  1815. blktrace is a tool for tracing and reporting low-level disk I/O.
  1816. blktrace provides the tracing half of the equation; its output can be
  1817. piped into the blkparse program, which renders the data in a
  1818. human-readable form and does some basic analysis:
  1819. blktrace Setup
  1820. --------------
  1821. For this section, we'll assume you've already performed the basic setup
  1822. outlined in the ":ref:`profile-manual/intro:General Setup`"
  1823. section.
  1824. blktrace is an application that runs on the target system. You can run
  1825. the entire blktrace and blkparse pipeline on the target, or you can run
  1826. blktrace in 'listen' mode on the target and have blktrace and blkparse
  1827. collect and analyze the data on the host (see the
  1828. ":ref:`profile-manual/usage:Using blktrace Remotely`" section
  1829. below). For the rest of this section we assume you've to the host through SSH
  1830. and will be running blktrace on the target.
  1831. Basic blktrace Usage
  1832. --------------------
  1833. To record a trace, just run the ``blktrace`` command, giving it the name
  1834. of the block device you want to trace activity on::
  1835. root@crownbay:~# blktrace /dev/sdc
  1836. In another shell, execute a workload you want to trace::
  1837. root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2; sync
  1838. Connecting to downloads.yoctoproject.org (140.211.169.59:80)
  1839. linux-2.6.19.2.tar.b 100% \|*******************************\| 41727k 0:00:00 ETA
  1840. Press ``Ctrl-C`` in the blktrace shell to stop the trace. It
  1841. will display how many events were logged, along with the per-cpu file
  1842. sizes (blktrace records traces in per-cpu kernel buffers and just
  1843. dumps them to user space for blkparse to merge and sort later)::
  1844. ^C=== sdc ===
  1845. CPU 0: 7082 events, 332 KiB data
  1846. CPU 1: 1578 events, 74 KiB data
  1847. Total: 8660 events (dropped 0), 406 KiB data
  1848. If you examine the files saved to disk, you see multiple files, one per CPU and
  1849. with the device name as the first part of the filename::
  1850. root@crownbay:~# ls -al
  1851. drwxr-xr-x 6 root root 1024 Oct 27 22:39 .
  1852. drwxr-sr-x 4 root root 1024 Oct 26 18:24 ..
  1853. -rw-r--r-- 1 root root 339938 Oct 27 22:40 sdc.blktrace.0
  1854. -rw-r--r-- 1 root root 75753 Oct 27 22:40 sdc.blktrace.1
  1855. To view the trace events, just call ``blkparse`` in the directory
  1856. containing the trace files, giving it the device name that forms the
  1857. first part of the filenames::
  1858. root@crownbay:~# blkparse sdc
  1859. 8,32 1 1 0.000000000 1225 Q WS 3417048 + 8 [jbd2/sdc-8]
  1860. 8,32 1 2 0.000025213 1225 G WS 3417048 + 8 [jbd2/sdc-8]
  1861. 8,32 1 3 0.000033384 1225 P N [jbd2/sdc-8]
  1862. 8,32 1 4 0.000043301 1225 I WS 3417048 + 8 [jbd2/sdc-8]
  1863. 8,32 1 0 0.000057270 0 m N cfq1225 insert_request
  1864. 8,32 1 0 0.000064813 0 m N cfq1225 add_to_rr
  1865. 8,32 1 5 0.000076336 1225 U N [jbd2/sdc-8] 1
  1866. 8,32 1 0 0.000088559 0 m N cfq workload slice:150
  1867. 8,32 1 0 0.000097359 0 m N cfq1225 set_active wl_prio:0 wl_type:1
  1868. 8,32 1 0 0.000104063 0 m N cfq1225 Not idling. st->count:1
  1869. 8,32 1 0 0.000112584 0 m N cfq1225 fifo= (null)
  1870. 8,32 1 0 0.000118730 0 m N cfq1225 dispatch_insert
  1871. 8,32 1 0 0.000127390 0 m N cfq1225 dispatched a request
  1872. 8,32 1 0 0.000133536 0 m N cfq1225 activate rq, drv=1
  1873. 8,32 1 6 0.000136889 1225 D WS 3417048 + 8 [jbd2/sdc-8]
  1874. 8,32 1 7 0.000360381 1225 Q WS 3417056 + 8 [jbd2/sdc-8]
  1875. 8,32 1 8 0.000377422 1225 G WS 3417056 + 8 [jbd2/sdc-8]
  1876. 8,32 1 9 0.000388876 1225 P N [jbd2/sdc-8]
  1877. 8,32 1 10 0.000397886 1225 Q WS 3417064 + 8 [jbd2/sdc-8]
  1878. 8,32 1 11 0.000404800 1225 M WS 3417064 + 8 [jbd2/sdc-8]
  1879. 8,32 1 12 0.000412343 1225 Q WS 3417072 + 8 [jbd2/sdc-8]
  1880. 8,32 1 13 0.000416533 1225 M WS 3417072 + 8 [jbd2/sdc-8]
  1881. 8,32 1 14 0.000422121 1225 Q WS 3417080 + 8 [jbd2/sdc-8]
  1882. 8,32 1 15 0.000425194 1225 M WS 3417080 + 8 [jbd2/sdc-8]
  1883. 8,32 1 16 0.000431968 1225 Q WS 3417088 + 8 [jbd2/sdc-8]
  1884. 8,32 1 17 0.000435251 1225 M WS 3417088 + 8 [jbd2/sdc-8]
  1885. 8,32 1 18 0.000440279 1225 Q WS 3417096 + 8 [jbd2/sdc-8]
  1886. 8,32 1 19 0.000443911 1225 M WS 3417096 + 8 [jbd2/sdc-8]
  1887. 8,32 1 20 0.000450336 1225 Q WS 3417104 + 8 [jbd2/sdc-8]
  1888. 8,32 1 21 0.000454038 1225 M WS 3417104 + 8 [jbd2/sdc-8]
  1889. 8,32 1 22 0.000462070 1225 Q WS 3417112 + 8 [jbd2/sdc-8]
  1890. 8,32 1 23 0.000465422 1225 M WS 3417112 + 8 [jbd2/sdc-8]
  1891. 8,32 1 24 0.000474222 1225 I WS 3417056 + 64 [jbd2/sdc-8]
  1892. 8,32 1 0 0.000483022 0 m N cfq1225 insert_request
  1893. 8,32 1 25 0.000489727 1225 U N [jbd2/sdc-8] 1
  1894. 8,32 1 0 0.000498457 0 m N cfq1225 Not idling. st->count:1
  1895. 8,32 1 0 0.000503765 0 m N cfq1225 dispatch_insert
  1896. 8,32 1 0 0.000512914 0 m N cfq1225 dispatched a request
  1897. 8,32 1 0 0.000518851 0 m N cfq1225 activate rq, drv=2
  1898. .
  1899. .
  1900. .
  1901. 8,32 0 0 58.515006138 0 m N cfq3551 complete rqnoidle 1
  1902. 8,32 0 2024 58.516603269 3 C WS 3156992 + 16 [0]
  1903. 8,32 0 0 58.516626736 0 m N cfq3551 complete rqnoidle 1
  1904. 8,32 0 0 58.516634558 0 m N cfq3551 arm_idle: 8 group_idle: 0
  1905. 8,32 0 0 58.516636933 0 m N cfq schedule dispatch
  1906. 8,32 1 0 58.516971613 0 m N cfq3551 slice expired t=0
  1907. 8,32 1 0 58.516982089 0 m N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80
  1908. 8,32 1 0 58.516985511 0 m N cfq3551 del_from_rr
  1909. 8,32 1 0 58.516990819 0 m N cfq3551 put_queue
  1910. CPU0 (sdc):
  1911. Reads Queued: 0, 0KiB Writes Queued: 331, 26,284KiB
  1912. Read Dispatches: 0, 0KiB Write Dispatches: 485, 40,484KiB
  1913. Reads Requeued: 0 Writes Requeued: 0
  1914. Reads Completed: 0, 0KiB Writes Completed: 511, 41,000KiB
  1915. Read Merges: 0, 0KiB Write Merges: 13, 160KiB
  1916. Read depth: 0 Write depth: 2
  1917. IO unplugs: 23 Timer unplugs: 0
  1918. CPU1 (sdc):
  1919. Reads Queued: 0, 0KiB Writes Queued: 249, 15,800KiB
  1920. Read Dispatches: 0, 0KiB Write Dispatches: 42, 1,600KiB
  1921. Reads Requeued: 0 Writes Requeued: 0
  1922. Reads Completed: 0, 0KiB Writes Completed: 16, 1,084KiB
  1923. Read Merges: 0, 0KiB Write Merges: 40, 276KiB
  1924. Read depth: 0 Write depth: 2
  1925. IO unplugs: 30 Timer unplugs: 1
  1926. Total (sdc):
  1927. Reads Queued: 0, 0KiB Writes Queued: 580, 42,084KiB
  1928. Read Dispatches: 0, 0KiB Write Dispatches: 527, 42,084KiB
  1929. Reads Requeued: 0 Writes Requeued: 0
  1930. Reads Completed: 0, 0KiB Writes Completed: 527, 42,084KiB
  1931. Read Merges: 0, 0KiB Write Merges: 53, 436KiB
  1932. IO unplugs: 53 Timer unplugs: 1
  1933. Throughput (R/W): 0KiB/s / 719KiB/s
  1934. Events (sdc): 6,592 entries
  1935. Skips: 0 forward (0 - 0.0%)
  1936. Input file sdc.blktrace.0 added
  1937. Input file sdc.blktrace.1 added
  1938. The report shows each event that was
  1939. found in the blktrace data, along with a summary of the overall block
  1940. I/O traffic during the run. You can look at the
  1941. `blkparse <https://linux.die.net/man/1/blkparse>`__ manual page to learn the
  1942. meaning of each field displayed in the trace listing.
  1943. Live Mode
  1944. ~~~~~~~~~
  1945. blktrace and blkparse are designed from the ground up to be able to
  1946. operate together in a "pipe mode" where the standard output of blktrace can be
  1947. fed directly into the standard input of blkparse::
  1948. root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -
  1949. This enables long-lived tracing sessions
  1950. to run without writing anything to disk, and allows the user to look for
  1951. certain conditions in the trace data in 'real-time' by viewing the trace
  1952. output as it scrolls by on the screen or by passing it along to yet
  1953. another program in the pipeline such as grep which can be used to
  1954. identify and capture conditions of interest.
  1955. There's actually another blktrace command that implements the above
  1956. pipeline as a single command, so the user doesn't have to bother typing
  1957. in the above command sequence::
  1958. root@crownbay:~# btrace /dev/sdc
  1959. Using blktrace Remotely
  1960. ~~~~~~~~~~~~~~~~~~~~~~~
  1961. Because blktrace traces block I/O and at the same time normally writes
  1962. its trace data to a block device, and in general because it's not really
  1963. a great idea to make the device being traced the same as the device the
  1964. tracer writes to, blktrace provides a way to trace without perturbing
  1965. the traced device at all by providing native support for sending all
  1966. trace data over the network.
  1967. To have blktrace operate in this mode, start blktrace in server mode on the
  1968. host system, which is going to store the captured data::
  1969. $ blktrace -l
  1970. server: waiting for connections...
  1971. On the target system that is going to be traced, start blktrace in client
  1972. mode with the -h option to connect to the host system, also passing it the
  1973. device to trace::
  1974. root@crownbay:~# blktrace -d /dev/sdc -h 192.168.1.43
  1975. blktrace: connecting to 192.168.1.43
  1976. blktrace: connected!
  1977. On the host system, you should see this::
  1978. server: connection from 192.168.1.43
  1979. In another shell, execute a workload you want to trace::
  1980. root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2; sync
  1981. Connecting to downloads.yoctoproject.org (140.211.169.59:80)
  1982. linux-2.6.19.2.tar.b 100% \|*******************************\| 41727k 0:00:00 ETA
  1983. When it's done, do a ``Ctrl-C`` on the target system to stop the
  1984. trace::
  1985. ^C=== sdc ===
  1986. CPU 0: 7691 events, 361 KiB data
  1987. CPU 1: 4109 events, 193 KiB data
  1988. Total: 11800 events (dropped 0), 554 KiB data
  1989. On the host system, you should also see a trace summary for the trace
  1990. just ended::
  1991. server: end of run for 192.168.1.43:sdc
  1992. === sdc ===
  1993. CPU 0: 7691 events, 361 KiB data
  1994. CPU 1: 4109 events, 193 KiB data
  1995. Total: 11800 events (dropped 0), 554 KiB data
  1996. The blktrace instance on the host will
  1997. save the target output inside a ``<hostname>-<timestamp>`` directory::
  1998. $ ls -al
  1999. drwxr-xr-x 10 root root 1024 Oct 28 02:40 .
  2000. drwxr-sr-x 4 root root 1024 Oct 26 18:24 ..
  2001. drwxr-xr-x 2 root root 1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56
  2002. ``cd`` into that directory to see the output files::
  2003. $ ls -l
  2004. -rw-r--r-- 1 root root 369193 Oct 28 02:44 sdc.blktrace.0
  2005. -rw-r--r-- 1 root root 197278 Oct 28 02:44 sdc.blktrace.1
  2006. And run blkparse on the host system using the device name::
  2007. $ blkparse sdc
  2008. 8,32 1 1 0.000000000 1263 Q RM 6016 + 8 [ls]
  2009. 8,32 1 0 0.000036038 0 m N cfq1263 alloced
  2010. 8,32 1 2 0.000039390 1263 G RM 6016 + 8 [ls]
  2011. 8,32 1 3 0.000049168 1263 I RM 6016 + 8 [ls]
  2012. 8,32 1 0 0.000056152 0 m N cfq1263 insert_request
  2013. 8,32 1 0 0.000061600 0 m N cfq1263 add_to_rr
  2014. 8,32 1 0 0.000075498 0 m N cfq workload slice:300
  2015. .
  2016. .
  2017. .
  2018. 8,32 0 0 177.266385696 0 m N cfq1267 arm_idle: 8 group_idle: 0
  2019. 8,32 0 0 177.266388140 0 m N cfq schedule dispatch
  2020. 8,32 1 0 177.266679239 0 m N cfq1267 slice expired t=0
  2021. 8,32 1 0 177.266689297 0 m N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56
  2022. 8,32 1 0 177.266692649 0 m N cfq1267 del_from_rr
  2023. 8,32 1 0 177.266696560 0 m N cfq1267 put_queue
  2024. CPU0 (sdc):
  2025. Reads Queued: 0, 0KiB Writes Queued: 270, 21,708KiB
  2026. Read Dispatches: 59, 2,628KiB Write Dispatches: 495, 39,964KiB
  2027. Reads Requeued: 0 Writes Requeued: 0
  2028. Reads Completed: 90, 2,752KiB Writes Completed: 543, 41,596KiB
  2029. Read Merges: 0, 0KiB Write Merges: 9, 344KiB
  2030. Read depth: 2 Write depth: 2
  2031. IO unplugs: 20 Timer unplugs: 1
  2032. CPU1 (sdc):
  2033. Reads Queued: 688, 2,752KiB Writes Queued: 381, 20,652KiB
  2034. Read Dispatches: 31, 124KiB Write Dispatches: 59, 2,396KiB
  2035. Reads Requeued: 0 Writes Requeued: 0
  2036. Reads Completed: 0, 0KiB Writes Completed: 11, 764KiB
  2037. Read Merges: 598, 2,392KiB Write Merges: 88, 448KiB
  2038. Read depth: 2 Write depth: 2
  2039. IO unplugs: 52 Timer unplugs: 0
  2040. Total (sdc):
  2041. Reads Queued: 688, 2,752KiB Writes Queued: 651, 42,360KiB
  2042. Read Dispatches: 90, 2,752KiB Write Dispatches: 554, 42,360KiB
  2043. Reads Requeued: 0 Writes Requeued: 0
  2044. Reads Completed: 90, 2,752KiB Writes Completed: 554, 42,360KiB
  2045. Read Merges: 598, 2,392KiB Write Merges: 97, 792KiB
  2046. IO unplugs: 72 Timer unplugs: 1
  2047. Throughput (R/W): 15KiB/s / 238KiB/s
  2048. Events (sdc): 9,301 entries
  2049. Skips: 0 forward (0 - 0.0%)
  2050. You should see the trace events and summary just as you would have if you'd run
  2051. the same command on the target.
  2052. Tracing Block I/O via 'ftrace'
  2053. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2054. It's also possible to trace block I/O using only
  2055. :ref:`profile-manual/usage:The 'trace events' Subsystem`, which
  2056. can be useful for casual tracing if you don't want to bother dealing with the
  2057. user space tools.
  2058. To enable tracing for a given device, use ``/sys/block/xxx/trace/enable``,
  2059. where ``xxx`` is the device name. This for example enables tracing for
  2060. ``/dev/sdc``::
  2061. root@crownbay:/sys/kernel/debug/tracing# echo 1 > /sys/block/sdc/trace/enable
  2062. Once you've selected the device(s) you want
  2063. to trace, selecting the ``blk`` tracer will turn the blk tracer on::
  2064. root@crownbay:/sys/kernel/debug/tracing# cat available_tracers
  2065. blk function_graph function nop
  2066. root@crownbay:/sys/kernel/debug/tracing# echo blk > current_tracer
  2067. Execute the workload you're interested in::
  2068. root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt
  2069. And look at the output (note here that we're using ``trace_pipe`` instead of
  2070. trace to capture this trace --- this allows us to wait around on the pipe
  2071. for data to appear)::
  2072. root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe
  2073. cat-3587 [001] d..1 3023.276361: 8,32 Q R 1699848 + 8 [cat]
  2074. cat-3587 [001] d..1 3023.276410: 8,32 m N cfq3587 alloced
  2075. cat-3587 [001] d..1 3023.276415: 8,32 G R 1699848 + 8 [cat]
  2076. cat-3587 [001] d..1 3023.276424: 8,32 P N [cat]
  2077. cat-3587 [001] d..2 3023.276432: 8,32 I R 1699848 + 8 [cat]
  2078. cat-3587 [001] d..1 3023.276439: 8,32 m N cfq3587 insert_request
  2079. cat-3587 [001] d..1 3023.276445: 8,32 m N cfq3587 add_to_rr
  2080. cat-3587 [001] d..2 3023.276454: 8,32 U N [cat] 1
  2081. cat-3587 [001] d..1 3023.276464: 8,32 m N cfq workload slice:150
  2082. cat-3587 [001] d..1 3023.276471: 8,32 m N cfq3587 set_active wl_prio:0 wl_type:2
  2083. cat-3587 [001] d..1 3023.276478: 8,32 m N cfq3587 fifo= (null)
  2084. cat-3587 [001] d..1 3023.276483: 8,32 m N cfq3587 dispatch_insert
  2085. cat-3587 [001] d..1 3023.276490: 8,32 m N cfq3587 dispatched a request
  2086. cat-3587 [001] d..1 3023.276497: 8,32 m N cfq3587 activate rq, drv=1
  2087. cat-3587 [001] d..2 3023.276500: 8,32 D R 1699848 + 8 [cat]
  2088. And this turns off tracing for the specified device::
  2089. root@crownbay:/sys/kernel/debug/tracing# echo 0 > /sys/block/sdc/trace/enable
  2090. blktrace Documentation
  2091. ----------------------
  2092. Online versions of the manual pages for the commands discussed in this
  2093. section can be found here:
  2094. - https://linux.die.net/man/8/blktrace
  2095. - https://linux.die.net/man/1/blkparse
  2096. - https://linux.die.net/man/8/btrace
  2097. The above manual pages, along with manuals for the other blktrace utilities
  2098. (``btt``, ``blkiomon``, etc) can be found in the ``/doc`` directory of the blktrace
  2099. tools git repository::
  2100. $ git clone git://git.kernel.dk/blktrace.git