From patchwork Tue Dec 1 15:22:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trevor Woerner X-Patchwork-Id: 106822 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.13175.1796138596668854718 for ; Tue, 01 Dec 2026 07:23:16 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20260707 header.b=OPPMJYwg; spf=pass (domain: gmail.com, ip: 209.85.167.180, mailfrom: twoerner@gmail.com) Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-57728d859e9so5119133b6e.1 for ; Tue, 01 Dec 2026 07:23:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796138596; x=1796743396; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=AtCZKbbuY1ag5OXiR6pqYWSZ2BuhbCTUlyjEEWAEypw=; b=OPPMJYwgL2nrHJYi5Onnvxxz290YW+DNTkD3VoAuRjBhV1rDHemZfdUVD1y+A44ZY8 nX5cEIzhjEnphwdFzYAMSks69cR/hqVIquZBhPJLtbw1E2NXGyokvVGtdzus71/oQWYS EzntA7VFLozF/W8DC9rb0H3Fdk5x82z1K+CHy71DrbjCeePxyIEZmkeekES4zHMV2DH9 TA0Sf7rHneRb3Jpun3ex8IhUKCOsKd+h03JV/ytPYiXVZtTXvAiZBKBoLUYMMqKIfnL+ vVAICY8ZsfFA0fhDZf3H/v5Y8y3V8BYoCxTj3/wLC2yFTAujDcHbhOnPu9V9OyahGIGM z1VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796138596; x=1796743396; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=AtCZKbbuY1ag5OXiR6pqYWSZ2BuhbCTUlyjEEWAEypw=; b=x5WV4hUMgWkse82bO5QrhPaYq1yUC/lVlg5AloSOriLJ53d8/WkOb9Wdz9WT29gM8P ZBSqN3wSUZ2Jil9REP2Ygt2mzLmlxM7TW1SzdbTqhO1eEg5M/GoL/re06IIgYQZsqznC s9XHicQDW6mNIfbIlSRXNefYb/tN/UKM6bblko7OIE1SQrs/YUub2unudFr4jj/PcXS/ dvgKuiNaDqqgeSiGBGuYuJdCBuVxCQ5Y+jCNWPuntCfKQijFA0x4WxJE8NziP0ExVKIO xJ1JVUkxkfuR8bMYxBX6GcU3MoSUE4k0cqdyIBWl3af10ai6bZ7VqOmTMYZIRJ99NgbC 43lg== X-Gm-Message-State: APuU4Z/uY8r4pgYWmZoucGH+wyJ5jHevQ+QXrsiAzITuFYkQmgNfC5U1 ez1Ju6/qyvNrVXRSdc+46Y/slmbX5Q9o50oIhl426Fd1NBZVayhOkpBwqk/+9Q== X-Gm-Gg: AZFdTZeV6a4+7iMsIqGIsNIyzwvMP5TXtnMZU6OsUkjcm91lHbSJ3LeUzi2gxhJVJun zaG3DKyhK0nET0lr5yOWz6XzcvMEyQPeu0cGvjpwUnN1Tzj//+40NRax6T8brPK+WAwO7GQ0f8l rJPwHykBxrX82cvyOgw9QAYcrxOz3p5BeBUOmbo5SqH7D5rhX5jxAP3aC+AFoSoVVS6flePu7lR aAXsljt7grI/dwdO9Xnzd0PHIU/rF5bZetbx8hsByXTSJRi/BgagA9w/cnreJprrHFtI+kvUE1D nUdPhSP5jTKHShTX5KDxCLBG19srkQGfUypTMAEaqrNmWgORvmHFjLFBv/BN1//EAVk7MsnkcrP 5w8qGH2u7bWrxPyKiZXNn7+UYu0+xfxzoLi7Yfmawlqne+zLCVcv8xdC69ogmwxSQbPq2FW4zWP mwfXppC86h8Ll8JonZUJ9gX88OFgocw72HQXcJV8cwgIGnKHQVIHn+s5u21IYnk0Ui22N4Z9AjB P7k61+QONeqGyPWQoX4gxlvqi5YXDN05fkRzQ+gYAefMfjr4uiEON8e90p85pXbPgiTc2VBYm+v I8F44iiizo6A4Mq9d5yyUro6T4bMRMyu8Vo2+f96uShQSNTrcL7ekay21ASXx8c2isqXizStj7K W+aCWPQLU3itaMewfK1ACSz8pF6yit90= X-Received: by 2002:a05:6808:1712:b0:579:f58e:bf8d with SMTP id 5614622812f47-57a0a20af6amr36982157b6e.20.1796138594852; Tue, 01 Dec 2026 07:23:14 -0800 (PST) Return-Path: Received: from localhost.localdomain (pppoe-209-91-167-254.vianet.ca. [209.91.167.254]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a31929223sm27818249b6e.1.2026.12.01.07.23.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 07:23:12 -0800 (PST) From: Trevor Woerner To: docs@lists.yoctoproject.org Subject: [PATCH 08/16] profile-manual: state the language of the blocks that are not BitBake Date: Tue, 1 Dec 2026 10:22:41 -0500 Message-ID: <20261201152251.2742634-9-twoerner@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261201152251.2742634-1-twoerner@gmail.com> References: <20261201152251.2742634-1-twoerner@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Tue, 01 Dec 2026 15:23:21 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/docs/message/10867 The manuals are moving to a default of bitbake for code blocks, so a BitBake block needs no language and every other block needs one. This gives the blocks in this manual that are not BitBake their language. AI-Generated: codex/claude-opus 5.5 (xhigh) Signed-off-by: Trevor Woerner --- documentation/profile-manual/intro.rst | 8 +- documentation/profile-manual/usage.rst | 384 ++++++++++++++++++------- 2 files changed, 294 insertions(+), 98 deletions(-) diff --git a/documentation/profile-manual/intro.rst b/documentation/profile-manual/intro.rst index e0c7fd5e5caa..fdc8e23f7d75 100644 --- a/documentation/profile-manual/intro.rst +++ b/documentation/profile-manual/intro.rst @@ -36,7 +36,9 @@ after adding ``tools-profile`` to the :term:`EXTRA_IMAGE_FEATURES` variable. So, in order to be able to access all of the tools described here, you can build and boot -an ``sdk`` image, perhaps one of:: +an ``sdk`` image, perhaps one of: + +.. code-block:: console $ bitbake core-image-sato-sdk $ bitbake core-image-weston-sdk @@ -48,7 +50,9 @@ your :ref:`structure-build-conf-local.conf` file:: EXTRA_IMAGE_FEATURES:append = " tools-profile" If you use the ``tools-profile`` method, you don't need to build an sdk image --- -the tracing and profiling tools will be included in non-sdk images as well e.g.:: +the tracing and profiling tools will be included in non-sdk images as well e.g.: + +.. code-block:: console $ bitbake core-image-sato diff --git a/documentation/profile-manual/usage.rst b/documentation/profile-manual/usage.rst index 7fdbe41da5e7..c9397816f973 100644 --- a/documentation/profile-manual/usage.rst +++ b/documentation/profile-manual/usage.rst @@ -62,7 +62,9 @@ Basic perf Usage The perf tool is pretty much self-documenting. To remind yourself of the available commands, just type ``perf``, which will show you basic usage -along with the available perf subcommands:: +along with the available perf subcommands: + +.. code-block:: console root@crownbay:~# perf @@ -102,7 +104,9 @@ which is a minimally interesting case because it has both file and network I/O aspects, and at least in the case of standard Yocto images, it's implemented as part of BusyBox, so the methods we use to analyze it can be used in a similar way to the whole host of supported BusyBox -applets in Yocto:: +applets in Yocto: + +.. code-block:: console root@crownbay:~# rm linux-2.6.19.2.tar.bz2; \ wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2 @@ -110,7 +114,9 @@ applets in Yocto:: The quickest and easiest way to get some basic overall data about what's going on for a particular workload is to profile it using ``perf stat``. This command basically profiles using a few default counters and displays -the summed counts at the end of the run:: +the summed counts at the end of the run: + +.. code-block:: console root@crownbay:~# perf stat wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2 Connecting to downloads.yoctoproject.org (140.211.169.59:80) @@ -139,7 +145,9 @@ Also, note that ``perf stat`` isn't restricted to a fixed set of counters --- basically any event listed in the output of ``perf list`` can be tallied by ``perf stat``. For example, suppose we wanted to see a summary of all the events related to kernel memory allocation/freeing along with cache -hits and misses:: +hits and misses: + +.. code-block:: console 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 Connecting to downloads.yoctoproject.org (140.211.169.59:80) @@ -179,7 +187,9 @@ record``, handing it the workload we want to profile (everything after ``perf record`` and any perf options we hand it --- here none, will be executed in a new shell). perf collects samples until the process exits and records them in a file named ``perf.data`` in the current working -directory:: +directory: + +.. code-block:: console root@crownbay:~# perf record wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2 @@ -191,7 +201,9 @@ directory:: To see the results in a "text-based UI" (tui), just run ``perf report``, which will read the perf.data file in the current working directory and display the results -in an interactive UI:: +in an interactive UI: + +.. code-block:: console root@crownbay:~# perf report @@ -218,7 +230,9 @@ Before we do that, however, let's try running a different profile, one which shows something a little more interesting. The only difference between the new profile and the previous one is that we'll add the ``-g`` option, which will record not just the address of a sampled function, -but the entire call chain to the sampled function as well:: +but the entire call chain to the sampled function as well: + +.. code-block:: console root@crownbay:~# perf record -g wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2 Connecting to downloads.yoctoproject.org (140.211.169.59:80) @@ -320,12 +334,16 @@ in a :term:`configuration file`:: Once we've done that, we can install the debugging information for BusyBox. The debug packages once built can be found in ``build/tmp/deploy/rpm/*`` on the host system. Find the ``busybox-dbg-...rpm`` file and copy it -to the target. For example:: +to the target. For example: + +.. code-block:: console $ scp /home/user/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2_32/busybox-dbg-1.20.2-r2.core2_32.rpm root@192.168.1.31: busybox-dbg-1.20.2-r2.core2_32.rpm 100% 1826KB 1.8MB/s 00:01 -Now install the debug RPM on the target:: +Now install the debug RPM on the target: + +.. code-block:: console root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2_32.rpm @@ -392,7 +410,9 @@ traditional tools can now actually make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously). We can get a list of the available events that can be used to profile a -workload via ``perf list``:: +workload via ``perf list``: + +.. code-block:: console root@crownbay:~# perf list @@ -535,7 +555,9 @@ workload via ``perf list``:: Only a subset of these would be of interest to us when looking at this workload, so let's choose the most likely subsystems (identified by the string before the colon in the ``Tracepoint`` events) and do a ``perf stat`` -run using only those subsystem wildcards:: +run using only those subsystem wildcards: + +.. code-block:: console 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 Performance counter stats for 'wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2': @@ -597,7 +619,9 @@ run using only those subsystem wildcards:: Let's pick one of these tracepoints -and tell perf to do a profile using it as the sampling event:: +and tell perf to do a profile using it as the sampling event: + +.. code-block:: console root@crownbay:~# perf record -g -e sched:sched_wakeup wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2 @@ -655,14 +679,18 @@ individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data. As a concrete example, we can trace all the events we think might be -applicable to our workload:: +applicable to our workload: + +.. code-block:: console root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:* -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2 We can look at the raw trace output using ``perf script`` with no -arguments:: +arguments: + +.. code-block:: console root@crownbay:~# perf script @@ -746,7 +774,9 @@ two programming language bindings, one for Python and one for Perl. Now that we have the trace data in ``perf.data``, we can use ``perf script -g`` to generate a skeleton script with handlers for the read / write -entry / exit events we recorded:: +entry / exit events we recorded: + +.. code-block:: console root@crownbay:~# perf script -g python generated Python script: perf-script.py @@ -766,7 +796,9 @@ with its parameters. For example: print "skbaddr=%u, len=%u, name=%s\n" % (skbaddr, len, name), We can run that script directly to print all of the events contained in the -``perf.data`` file:: +``perf.data`` file: + +.. code-block:: console root@crownbay:~# perf script -s perf-script.py @@ -844,7 +876,9 @@ result of all the per-event tallies. For that, we use the special for event_name, count in counts.iteritems(): print "%-40s %10s\n" % (event_name, count) -The end result is a summary of all the events recorded in the trace:: +The end result is a summary of all the events recorded in the trace: + +.. code-block:: text skb__skb_copy_datagram_iovec 13148 irq__softirq_entry 4796 @@ -888,13 +922,17 @@ To do system-wide profiling or tracing, you typically use the ``-a`` flag to ``perf record``. To demonstrate this, open up one window and start the profile using the -``-a`` flag (press ``Ctrl-C`` to stop tracing):: +``-a`` flag (press ``Ctrl-C`` to stop tracing): + +.. code-block:: console root@crownbay:~# perf record -g -a ^C[ perf record: Woken up 6 times to write data ] [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ] -In another window, run the ``wget`` test:: +In another window, run the ``wget`` test: + +.. code-block:: console root@crownbay:~# wget &YOCTO_DL_URL;/mirror/sources/linux-2.6.19.2.tar.bz2 Connecting to downloads.yoctoproject.org (140.211.169.59:80) @@ -915,7 +953,9 @@ unresolvable symbols in the expanded ``Xorg`` call chain). Note also that we have both kernel and user space entries in the above snapshot. We can also tell perf to focus on user space but providing a modifier, in this case ``u``, to the ``cycles`` hardware counter when we -record a profile:: +record a profile: + +.. code-block:: console root@crownbay:~# perf record -g -a -e cycles:u ^C[ perf record: Woken up 2 times to write data ] @@ -937,13 +977,17 @@ the entries associated with the ``libc-xxx.so`` DSO. :width: 70% We can also use the system-wide ``-a`` switch to do system-wide tracing. -Here we'll trace a couple of scheduler events:: +Here we'll trace a couple of scheduler events: + +.. code-block:: console root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup ^C[ perf record: Woken up 38 times to write data ] [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ] -We can look at the raw output using ``perf script`` with no arguments:: +We can look at the raw output using ``perf script`` with no arguments: + +.. code-block:: console root@crownbay:~# perf script @@ -966,7 +1010,9 @@ do with what we're interested in, namely events that schedule ``perf`` itself in and out or that wake perf up. We can get rid of those by using the ``--filter`` option --- for each event we specify using ``-e``, we can add a ``--filter`` after that to filter out trace events that contain fields with -specific values:: +specific values: + +.. code-block:: console root@crownbay:~# perf record -a -e sched:sched_switch --filter 'next_comm != perf && prev_comm != perf' -e sched:sched_wakeup --filter 'comm != perf' ^C[ perf record: Woken up 38 times to write data ] @@ -1031,7 +1077,9 @@ perf isn't restricted to the fixed set of static tracepoints listed by ``perf list``. Users can also add their own "dynamic" tracepoints anywhere in the kernel. For example, suppose we want to define our own tracepoint on ``do_fork()``. We can do that using the ``perf probe`` perf -subcommand:: +subcommand: + +.. code-block:: console root@crownbay:~# perf probe do_fork Added new event: @@ -1045,7 +1093,9 @@ Adding a new tracepoint via ``perf probe`` results in an event with all the expected files and format in ``/sys/kernel/debug/tracing/events``, just the same as for static tracepoints (as discussed in more detail in the trace events subsystem -section:: +section: + +.. code-block:: console root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al drwxr-xr-x 2 root root 0 Oct 28 11:42 . @@ -1070,7 +1120,9 @@ section:: print fmt: "(%lx)", REC->__probe_ip We can list all dynamic tracepoints currently in -existence:: +existence: + +.. code-block:: console root@crownbay:~# perf probe -l probe:do_fork (on do_fork) @@ -1078,13 +1130,17 @@ existence:: Let's record system-wide (``sleep 30`` is a trick for recording system-wide but basically do nothing and then wake -up after 30 seconds):: +up after 30 seconds): + +.. code-block:: console root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ] -Using ``perf script`` we can see each ``do_fork`` event that fired:: +Using ``perf script`` we can see each ``do_fork`` event that fired: + +.. code-block:: console root@crownbay:~# perf script @@ -1175,7 +1231,9 @@ configuration as follows:: DISTRO_FEATURES:append = " api-documentation" The manual pages in text form, along with some other files, such as a set -of examples, can also be found in the ``perf`` directory of the kernel tree:: +of examples, can also be found in the ``perf`` directory of the kernel tree: + +.. code-block:: text tools/perf/Documentation @@ -1209,7 +1267,9 @@ Basic ftrace usage "ftrace" essentially refers to everything included in the ``/tracing`` directory of the mounted debugfs filesystem (Yocto follows the standard convention and mounts it at ``/sys/kernel/debug``). All the files found in -``/sys/kernel/debug/tracing`` on a Yocto system are:: +``/sys/kernel/debug/tracing`` on a Yocto system are: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing# ls README kprobe_events trace @@ -1234,12 +1294,16 @@ the ftrace documentation. We'll start by looking at some of the available built-in tracers. -The ``available_tracers`` file lists the set of available tracers:: +The ``available_tracers`` file lists the set of available tracers: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers blk function_graph function nop -The ``current_tracer`` file contains the tracer currently in effect:: +The ``current_tracer`` file contains the tracer currently in effect: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer nop @@ -1249,7 +1313,9 @@ The above listing of ``current_tracer`` shows that the there's actually no tracer currently in effect. Writing one of the available tracers into ``current_tracer`` makes the -specified tracer the current tracer:: +specified tracer the current tracer: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing# echo function > current_tracer root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer @@ -1259,7 +1325,9 @@ The above sets the current tracer to be the ``function`` tracer. This tracer traces every function call in the kernel and makes it available as the contents of the ``trace`` file. Reading the ``trace`` file lists the currently buffered function calls that have been traced by the function -tracer:: +tracer: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing# cat trace | less @@ -1318,7 +1386,9 @@ great way to learn about how the kernel code works in a dynamic sense. It is a little more difficult to follow the call chains than it needs to be --- luckily there's a variant of the function tracer that displays the -call chains explicitly, called the ``function_graph`` tracer:: +call chains explicitly, called the ``function_graph`` tracer: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing# echo function_graph > current_tracer root@sugarbay:/sys/kernel/debug/tracing# cat trace | less @@ -1454,7 +1524,9 @@ One especially important directory contained within the ``/sys/kernel/debug/tracing`` directory is the ``events`` subdirectory, which contains representations of every tracepoint in the system. Listing out the contents of the ``events`` subdirectory, we see mainly another set of -subdirectories:: +subdirectories: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing# cd events root@sugarbay:/sys/kernel/debug/tracing/events# ls -al @@ -1503,7 +1575,9 @@ subdirectories:: Each one of these subdirectories corresponds to a "subsystem" and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint. For example, -here are the contents of the ``kmem`` subsystem:: +here are the contents of the ``kmem`` subsystem: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al @@ -1525,7 +1599,9 @@ here are the contents of the ``kmem`` subsystem:: drwxr-xr-x 2 root root 0 Nov 14 23:19 mm_page_pcpu_drain Let's see what's inside the subdirectory for a -specific tracepoint, in this case the one for ``kmalloc``:: +specific tracepoint, in this case the one for ``kmalloc``: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al @@ -1541,7 +1617,9 @@ tracepoint describes the event in memory, which is used by the various tracing tools that now make use of these tracepoint to parse the event and make sense of it, along with a ``print fmt`` field that allows tools like ftrace to display the event as text. The format of the -``kmalloc`` event looks like:: +``kmalloc`` event looks like: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format name: kmalloc @@ -1580,20 +1658,26 @@ The ``enable`` file in the tracepoint directory is what allows the user (or tools such as ``trace-cmd``) to actually turn the tracepoint on and off. When enabled, the corresponding tracepoint will start appearing in the ftrace ``trace`` file -described previously. For example, this turns on the ``kmalloc`` tracepoint:: +described previously. For example, this turns on the ``kmalloc`` tracepoint: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 > enable At the moment, we're not interested in the function tracer or some other tracer that might be in effect, so we first turn it off, but if we do that, we still need to turn tracing on in order to see the -events in the output buffer:: +events in the output buffer: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing# echo nop > current_tracer root@sugarbay:/sys/kernel/debug/tracing# echo 1 > tracing_on Now, if we look at the ``trace`` file, we see nothing -but the ``kmalloc`` events we just turned on:: +but the ``kmalloc`` events we just turned on: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing# cat trace | less # tracer: nop @@ -1639,7 +1723,9 @@ but the ``kmalloc`` events we just turned on:: -0 [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC 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 -To again disable the ``kmalloc`` event, we need to send ``0`` to the ``enable`` file:: +To again disable the ``kmalloc`` event, we need to send ``0`` to the ``enable`` file: + +.. code-block:: console root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 > enable @@ -1681,11 +1767,15 @@ a per-CPU graphical display. It directly uses trace-cmd as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we'll see). -To start a trace using KernelShark, first start this tool:: +To start a trace using KernelShark, first start this tool: + +.. code-block:: console root@sugarbay:~# kernelshark -Then open up the ``Capture`` dialog by choosing from the KernelShark menu:: +Then open up the ``Capture`` dialog by choosing from the KernelShark menu: + +.. code-block:: text Capture | Record @@ -1739,12 +1829,16 @@ ftrace Documentation -------------------- The documentation for ftrace can be found in the kernel Documentation -directory:: +directory: + +.. code-block:: text Documentation/trace/ftrace.txt The documentation for the trace event subsystem can also be found in the kernel -Documentation directory:: +Documentation directory: + +.. code-block:: text Documentation/trace/events.txt @@ -1799,7 +1893,9 @@ extracts from the argument string (``argstr``) of the ``open`` system call. Normally, to execute this probe, you'd just install SystemTap on the system you want to probe, and directly run the probe on that system e.g. assuming the name of the -file containing the above text is ``trace_open.stp``:: +file containing the above text is ``trace_open.stp``: + +.. code-block:: console root@machine:~# stap trace_open.stp @@ -1840,7 +1936,9 @@ target, with arguments if necessary. In order to do this from a remote host, however, you need to have access to the build for the image you booted. The ``crosstap`` script provides details on how to do this if you run the script on the host without -having done a build:: +having done a build: + +.. code-block:: console $ crosstap root@192.168.1.88 trace_open.stp @@ -1863,19 +1961,25 @@ Practically speaking, that means you need to do the following: the BSP README and/or the widely available basic documentation that discusses how to build images). -- Build an ``-sdk`` version of the image e.g.:: +- Build an ``-sdk`` version of the image e.g.: + + .. code-block:: console $ bitbake core-image-sato-sdk - Or build a non-SDK image but include the profiling tools (add ``tools-profile`` to the :term:`EXTRA_IMAGE_FEATURES` - variable):: + variable): + + .. code-block:: console $ bitbake core-image-sato Once you've build the image on the host system, you're ready to boot it (or the equivalent pre-built image) and use ``crosstap`` - to probe it (you need to source the environment as usual first):: + to probe it (you need to source the environment as usual first): + + .. code-block:: console $ source oe-init-build-env $ cd ~/my/systemtap/scripts @@ -1904,7 +2008,9 @@ Running a Script on a Target ---------------------------- Once you've done that, you should be able to run a SystemTap script on -the target:: +the target: + +.. code-block:: console $ cd /path/to/yocto $ source oe-init-build-env @@ -1922,17 +2028,23 @@ the target:: You can also run generated QEMU images with a command like 'runqemu qemux86-64' Once you've done that, you can ``cd`` to whatever -directory contains your scripts and use ``crosstap`` to run the script:: +directory contains your scripts and use ``crosstap`` to run the script: + +.. code-block:: console $ cd /path/to/my/systemap/script $ crosstap root@192.168.7.2 trace_open.stp -If you get an error connecting to the target e.g.:: +If you get an error connecting to the target e.g.: + +.. code-block:: console $ crosstap root@192.168.7.2 trace_open.stp error establishing ssh connection on remote 'root@192.168.7.2' -Try connecting to the target through SSH and see what happens:: +Try connecting to the target through SSH and see what happens: + +.. code-block:: console $ ssh root@192.168.7.2 @@ -2058,7 +2170,9 @@ tracing. Collecting and viewing a trace on the target (inside a shell) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -First, from the host, connect to the target through SSH:: +First, from the host, connect to the target through SSH: + +.. code-block:: console $ ssh -l root 192.168.1.47 The authenticity of host '192.168.1.47 (192.168.1.47)' can't be established. @@ -2067,30 +2181,40 @@ First, from the host, connect to the target through SSH:: Warning: Permanently added '192.168.1.47' (RSA) to the list of known hosts. root@192.168.1.47's password: -Once on the target, use these steps to create a trace:: +Once on the target, use these steps to create a trace: + +.. code-block:: console root@crownbay:~# lttng create Spawning a session daemon Session auto-20121015-232120 created. Traces will be written in /home/root/lttng-traces/auto-20121015-232120 -Enable the events you want to trace (in this case all kernel events):: +Enable the events you want to trace (in this case all kernel events): + +.. code-block:: console root@crownbay:~# lttng enable-event --kernel --all All kernel events are enabled in channel channel0 -Start the trace:: +Start the trace: + +.. code-block:: console root@crownbay:~# lttng start Tracing started for session auto-20121015-232120 And then stop the trace after awhile or after running a particular workload that -you want to trace:: +you want to trace: + +.. code-block:: console root@crownbay:~# lttng stop Tracing stopped for session auto-20121015-232120 -You can now view the trace in text form on the target:: +You can now view the trace in text form on the target: + +.. code-block:: console root@crownbay:~# lttng view [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { } @@ -2136,14 +2260,18 @@ You can now view the trace in text form on the target:: You can now safely destroy the trace session (note that this doesn't delete the trace --- it's still there in -``~/lttng-traces``):: +``~/lttng-traces``): + +.. code-block:: console root@crownbay:~# lttng destroy Session auto-20121015-232120 destroyed at /home/root Note that the trace is saved in a directory of the same name as returned by ``lttng create``, under the ``~/lttng-traces`` directory (note that you can change this by -supplying your own name to ``lttng create``):: +supplying your own name to ``lttng create``): + +.. code-block:: console root@crownbay:~# ls -al ~/lttng-traces drwxrwx--- 3 root root 1024 Oct 15 23:21 . @@ -2159,18 +2287,24 @@ generated by the ``lttng-ust`` build. The ``hello`` test program isn't installed on the root filesystem by the ``lttng-ust`` build, so we need to copy it over manually. First ``cd`` into the build -directory that contains the ``hello`` executable:: +directory that contains the ``hello`` executable: + +.. code-block:: console $ cd build/tmp/work/core2_32-poky-linux/lttng-ust/2.0.5-r0/git/tests/hello/.libs -Copy that over to the target machine:: +Copy that over to the target machine: + +.. code-block:: console $ scp hello root@192.168.1.20: You now have the instrumented LTTng "hello world" test program on the target, ready to test. -First, from the host, connect to the target through SSH:: +First, from the host, connect to the target through SSH: + +.. code-block:: console $ ssh -l root 192.168.1.47 The authenticity of host '192.168.1.47 (192.168.1.47)' can't be established. @@ -2179,35 +2313,47 @@ First, from the host, connect to the target through SSH:: Warning: Permanently added '192.168.1.47' (RSA) to the list of known hosts. root@192.168.1.47's password: -Once on the target, use these steps to create a trace:: +Once on the target, use these steps to create a trace: + +.. code-block:: console root@crownbay:~# lttng create Session auto-20190303-021943 created. Traces will be written in /home/root/lttng-traces/auto-20190303-021943 -Enable the events you want to trace (in this case all user space events):: +Enable the events you want to trace (in this case all user space events): + +.. code-block:: console root@crownbay:~# lttng enable-event --userspace --all All UST events are enabled in channel channel0 -Start the trace:: +Start the trace: + +.. code-block:: console root@crownbay:~# lttng start Tracing started for session auto-20190303-021943 -Run the instrumented "hello world" program:: +Run the instrumented "hello world" program: + +.. code-block:: console root@crownbay:~# ./hello Hello, World! Tracing... done. And then stop the trace after awhile or after running a particular workload -that you want to trace:: +that you want to trace: + +.. code-block:: console root@crownbay:~# lttng stop Tracing stopped for session auto-20190303-021943 -You can now view the trace in text form on the target:: +You can now view the trace in text form on the target: + +.. code-block:: console root@crownbay:~# lttng view [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 } @@ -2219,7 +2365,9 @@ You can now view the trace in text form on the target:: . You can now safely destroy the trace session (note that this doesn't delete the -trace --- it's still there in ``~/lttng-traces``):: +trace --- it's still there in ``~/lttng-traces``): + +.. code-block:: console root@crownbay:~# lttng destroy Session auto-20190303-021943 destroyed at /home/root @@ -2264,11 +2412,15 @@ Basic blktrace Usage -------------------- To record a trace, just run the ``blktrace`` command, giving it the name -of the block device you want to trace activity on:: +of the block device you want to trace activity on: + +.. code-block:: console root@crownbay:~# blktrace /dev/sdc -In another shell, execute a workload you want to trace:: +In another shell, execute a workload you want to trace: + +.. code-block:: console 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 Connecting to downloads.yoctoproject.org (140.211.169.59:80) @@ -2277,7 +2429,9 @@ In another shell, execute a workload you want to trace:: Press ``Ctrl-C`` in the blktrace shell to stop the trace. It will display how many events were logged, along with the per-cpu file sizes (blktrace records traces in per-cpu kernel buffers and just -dumps them to user space for blkparse to merge and sort later):: +dumps them to user space for blkparse to merge and sort later): + +.. code-block:: text ^C=== sdc === CPU 0: 7082 events, 332 KiB data @@ -2285,7 +2439,9 @@ dumps them to user space for blkparse to merge and sort later):: Total: 8660 events (dropped 0), 406 KiB data If you examine the files saved to disk, you see multiple files, one per CPU and -with the device name as the first part of the filename:: +with the device name as the first part of the filename: + +.. code-block:: console root@crownbay:~# ls -al drwxr-xr-x 6 root root 1024 Oct 27 22:39 . @@ -2295,7 +2451,9 @@ with the device name as the first part of the filename:: To view the trace events, just call ``blkparse`` in the directory containing the trace files, giving it the device name that forms the -first part of the filenames:: +first part of the filenames: + +.. code-block:: console root@crownbay:~# blkparse sdc @@ -2393,7 +2551,9 @@ Live Mode blktrace and blkparse are designed from the ground up to be able to operate together in a "pipe mode" where the standard output of blktrace can be -fed directly into the standard input of blkparse:: +fed directly into the standard input of blkparse: + +.. code-block:: console root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i - @@ -2406,7 +2566,9 @@ identify and capture conditions of interest. There's actually another blktrace command that implements the above pipeline as a single command, so the user doesn't have to bother typing -in the above command sequence:: +in the above command sequence: + +.. code-block:: console root@crownbay:~# btrace /dev/sdc @@ -2421,31 +2583,41 @@ the traced device at all by providing native support for sending all trace data over the network. To have blktrace operate in this mode, start blktrace in server mode on the -host system, which is going to store the captured data:: +host system, which is going to store the captured data: + +.. code-block:: console $ blktrace -l server: waiting for connections... On the target system that is going to be traced, start blktrace in client mode with the -h option to connect to the host system, also passing it the -device to trace:: +device to trace: + +.. code-block:: console root@crownbay:~# blktrace -d /dev/sdc -h 192.168.1.43 blktrace: connecting to 192.168.1.43 blktrace: connected! -On the host system, you should see this:: +On the host system, you should see this: + +.. code-block:: text server: connection from 192.168.1.43 -In another shell, execute a workload you want to trace:: +In another shell, execute a workload you want to trace: + +.. code-block:: console 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 Connecting to downloads.yoctoproject.org (140.211.169.59:80) linux-2.6.19.2.tar.b 100% \|*******************************\| 41727k 0:00:00 ETA When it's done, do a ``Ctrl-C`` on the target system to stop the -trace:: +trace: + +.. code-block:: text ^C=== sdc === CPU 0: 7691 events, 361 KiB data @@ -2453,7 +2625,9 @@ trace:: Total: 11800 events (dropped 0), 554 KiB data On the host system, you should also see a trace summary for the trace -just ended:: +just ended: + +.. code-block:: text server: end of run for 192.168.1.43:sdc === sdc === @@ -2462,20 +2636,26 @@ just ended:: Total: 11800 events (dropped 0), 554 KiB data The blktrace instance on the host will -save the target output inside a ``-`` directory:: +save the target output inside a ``-`` directory: + +.. code-block:: console $ ls -al drwxr-xr-x 10 root root 1024 Oct 28 02:40 . drwxr-sr-x 4 root root 1024 Oct 26 18:24 .. drwxr-xr-x 2 root root 1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56 -``cd`` into that directory to see the output files:: +``cd`` into that directory to see the output files: + +.. code-block:: console $ ls -l -rw-r--r-- 1 root root 369193 Oct 28 02:44 sdc.blktrace.0 -rw-r--r-- 1 root root 197278 Oct 28 02:44 sdc.blktrace.1 -And run blkparse on the host system using the device name:: +And run blkparse on the host system using the device name: + +.. code-block:: console $ blkparse sdc @@ -2538,25 +2718,33 @@ user space tools. To enable tracing for a given device, use ``/sys/block/xxx/trace/enable``, where ``xxx`` is the device name. This for example enables tracing for -``/dev/sdc``:: +``/dev/sdc``: + +.. code-block:: console root@crownbay:/sys/kernel/debug/tracing# echo 1 > /sys/block/sdc/trace/enable Once you've selected the device(s) you want -to trace, selecting the ``blk`` tracer will turn the blk tracer on:: +to trace, selecting the ``blk`` tracer will turn the blk tracer on: + +.. code-block:: console root@crownbay:/sys/kernel/debug/tracing# cat available_tracers blk function_graph function nop root@crownbay:/sys/kernel/debug/tracing# echo blk > current_tracer -Execute the workload you're interested in:: +Execute the workload you're interested in: + +.. code-block:: console root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt And look at the output (note here that we're using ``trace_pipe`` instead of trace to capture this trace --- this allows us to wait around on the pipe -for data to appear):: +for data to appear): + +.. code-block:: console root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe cat-3587 [001] d..1 3023.276361: 8,32 Q R 1699848 + 8 [cat] @@ -2575,7 +2763,9 @@ for data to appear):: cat-3587 [001] d..1 3023.276497: 8,32 m N cfq3587 activate rq, drv=1 cat-3587 [001] d..2 3023.276500: 8,32 D R 1699848 + 8 [cat] -And this turns off tracing for the specified device:: +And this turns off tracing for the specified device: + +.. code-block:: console root@crownbay:/sys/kernel/debug/tracing# echo 0 > /sys/block/sdc/trace/enable @@ -2593,6 +2783,8 @@ section can be found here: The above manual pages, along with manuals for the other blktrace utilities (``btt``, ``blkiomon``, etc) can be found in the ``/doc`` directory of the blktrace -tools git repository:: +tools git repository: + +.. code-block:: console $ git clone https://git.kernel.org/pub/scm/linux/kernel/git/axboe/blktrace.git